zha: Clean up listener registration and button state#14197
zha: Clean up listener registration and button state#14197balloob merged 1 commit intohome-assistant:devfrom rcloran:zha-better-buttons
Conversation
There was a problem hiding this comment.
line too long (81 > 79 characters)
There was a problem hiding this comment.
For a future PR: add async_will_remove_from_hass and you're almost able to load/unload ZHA while Home Assistant is running 👍
There was a problem hiding this comment.
This is called from an async context?
There was a problem hiding this comment.
@MartinHjelmare's comments on #12528 suggested I should change this ... but, reading the code, it looks like I shouldn't be changing this. These are run from callbacks. Since async_... is a coro, I'd need to ensure it runs, and that's exactly what the schedule_... does.
There was a problem hiding this comment.
We need to know what is calling the callback, a thread or the event loop. That was my question.
There was a problem hiding this comment.
Ok, in that case async_schedule_update_ha_state() is ok
There was a problem hiding this comment.
Since that is a coro, doesn’t it need to be scheduled anyways?
There was a problem hiding this comment.
Doh, I was reading async_update_ha_state, not async_schedule_update_ha_state. Alright, this all makes much more sense now.
There was a problem hiding this comment.
This will reset the listeners added in the child. You can init the parent before the setting the rest of the child's attributes.
- Instead of registering listeners in the entity __init__, do it in async_added_to_hass to avoid errors updating an entity which isn't fully set up yet - Change from schedule_update_ha_state to async_schedule_update_ha_state
async_added_to_hass to avoid errors updating an entity which isn't fully
set up yet
Description:
Related issue (if applicable): fixes #
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: