Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Adds integration for Plaato Airlock #23727
Adds integration for Plaato Airlock #23727
Changes from 15 commits
1a99ecc
e28502e
e4e5be0
573276a
14f7ed2
c7ca696
39e2553
512e444
7d3585f
9579a2a
97a817e
bfde338
d5c1740
5b4ce0f
2a3d940
44810ea
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Pass
True
so that it will call theasync_update
method and fetch the latest data.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.
Alternative, since the data is just fetched from a dictionary stored in memory during update, you could have all properties fetch the data directly from that dictionary instead of storing it on the entity instance. In that case you can skip
True
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.
What you are suggesting would mean that I should move things from
async_update
to thestate
property? Something like this?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.
yeah. Just know that you cannot do any I/O inside properties.
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.
Done!
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's not safe to call
entity.async_schedule_update_ha_state
directly in non polling platforms.For polling platforms we can assume that the interval between polls is long enough so that all new entities will have been added to home assistant before the next update, via poll, is done and calls this method.
For non polling platforms we can't assume this. The next update for new entities might come immediately after the first one, before they have been added to home assistant. Then this call will error.
The safe approach in this case is to use our dispatch helper and send a signal to the entity to have it call
async_schedule_update_ha_state
from inside itself. The signal should be connected inasync_added_to_hass
which will guard from the error.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.
Thank @MartinHjelmare I will look into this. You don't happen to have any examples where this behavior is used? So I can learn how to do 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.
Something like this:
https://github.com/home-assistant/home-assistant/blob/f382be4c15ef32f557ba6d40bb01c084c5cbc692/homeassistant/components/aftership/sensor.py#L145-L153
In our case we might not even need an extra method that does the update call. We can connect
async_schedule_update_ha_state
directly. So replaceself.force_update
withself.async_schedule_update_ha_state
.Send the signal to update like so:
https://github.com/home-assistant/home-assistant/blob/f382be4c15ef32f557ba6d40bb01c084c5cbc692/homeassistant/components/aftership/sensor.py#L85
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.
@MartinHjelmare Thank you. I'll open up a new PR for this change.
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.
@MartinHjelmare PR with the changes you requested: #24627