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
Scaffold device automation #26871
Scaffold device automation #26871
Conversation
script/scaffold/templates/device_automation/integration/device_automation.py
Outdated
Show resolved
Hide resolved
|
||
async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]: | ||
"""List device triggers for NEW_NAME devices.""" | ||
registry = await entity_registry.async_get_registry(hass) |
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.
Should the script expose the ability to have both device and entity based triggers? Ex: in the case of stateless devices (remotes) there are no entities. Maybe pass the device to a private method to add device triggers, get the entities and then pass them to a private method to add entity triggers if necessary?
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've added a comment with some commented out code from the ZHA integration.
script/scaffold/templates/device_automation/integration/device_automation.py
Outdated
Show resolved
Hide resolved
) | ||
|
||
|
||
async def async_get_conditions(hass: HomeAssistant, device_id: str): |
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.
Same as above. Should this expose the ability to do this at both device and entity levels?
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.
We should aim for device conditions to be a layer on top of existing state conditions. We should not have device conditions that get data that is not available in the state machine.
return test_is_on | ||
|
||
|
||
async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]: |
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.
Same as above. Should this expose the ability to do this at both device and entity levels?
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.
Added a comment to the generated code. Let me know if you think that it's enough.
|
||
# Add triggers for each entity that belongs to this integration | ||
# TODO add your own triggers. It's ok to not have any triggers. | ||
triggers.append( |
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.
Should these blocks just be part of the comment above to illustrate how to do this? Or is there value in assuming/treating everything works like an on/off type of device? It looks like the script is designed to treat everything like a toggle entity.
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 was mainly to get tests going and show people how it should look.
You think that we should comment it out to emphasize that it's an example ?
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.
If you’re not worried that people will leave it in their implementations then leave it.
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.
Let's leave it in and see what the PRs do.
|
||
# Add conditions for each entity that belongs to this integration | ||
# TODO add your own conditions. It's ok to not have any conditions. | ||
conditions.append( |
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.
Same as above. Should this just be part of the comment?
|
||
# Add actions for each entity that belongs to this integration | ||
# TODO add your own actions. It's ok to not have any actions. | ||
actions.append( |
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.
Same as above. Should this just be part of the comment?
eb20b84
to
ae25772
Compare
I have updated the templates to match our new device automation organisation. It's now 3 templates : device_trigger, device_condition, device_action. |
ae25772
to
f0d9812
Compare
Description:
Scaffold script to bootstrap device automations.
python3 -m script.scaffold device_trigger
python3 -m script.scaffold device_condition
python3 -m script.scaffold device_action
Docs home-assistant/developers.home-assistant#321