-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update template switch to new format #128944
base: dev
Are you sure you want to change the base?
Update template switch to new format #128944
Conversation
Hey there @PhracturedBlue, @tetienne, @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
efc4262
to
7404c25
Compare
@@ -219,3 +297,90 @@ async def async_turn_off(self, **kwargs: Any) -> None: | |||
if self._template is None: | |||
self._state = False | |||
self.async_write_ha_state() | |||
|
|||
|
|||
class TriggerSwitchEntity(TriggerEntity, SwitchEntity, RestoreEntity): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to have an AbstractSwitchTemplate
class from which both SwitchTemplate
and TriggerSwitchEntity` inherit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a nice idea, however none of the existing template entities do this and there are challenges that arise. It is something that I want to do, but I want it to be done at a integration level, not domain level.
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Fire the on action.""" | ||
if self._on_script: | ||
await self.async_run_script(self._on_script, context=self._context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the need for a new method which takes the script as a parameter. Either async_run_script
should be defined in this class and grab the required script from the object properties OR just add this
as one of the variables when calling self._on_script.async_run(...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That new method will be used by all trigger based template entities (light, fan, select, etc) to provide the action scripts with the this
variable, just like non trigger based template entities. This function is needed to fix this long standing issue. It's added here first and it will be added to all other domains at a later date.
Hi there @Petro31 👋 There is a merge conflict, could you take a look? Thanks! 👍 ../Frenck |
a97d21c
to
3e6c9d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing, can you take a look?
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
c301956
to
b54c34c
Compare
Breaking change
No
Proposed change
Add switch to new template yaml format
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: