-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Conversation
Please remove |
d115cca
to
135945e
Compare
Rebased on latest dev and fixed things for config flow. |
Any chance someone could look at this PR? |
async_add_entities(entities, True) | ||
else: | ||
for entity in devices[device_id]: | ||
entity.async_schedule_update_ha_state() |
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 the async_update
method and fetch the latest data.
entity.async_schedule_update_ha_state() | |
entity.async_schedule_update_ha_state(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.
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 the state
property? Something like this?
@property
def state(self):
"""Return the state of the sensor."""
sensors = self.get_sensors()
if sensors is False:
_LOGGER.debug("Device with name %s has no sensors.", self.name)
return 0
if self._type == ATTR_ABV:
return round(sensors.get(self._type), 2)
elif self._type == ATTR_TEMP:
return round(sensors.get(self._type), 1)
elif self._type == ATTR_CO2_VOLUME:
return round(sensors.get(self._type), 2)
else:
return sensors.get(self._type)
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 in async_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 replace self.force_update
with self.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
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.
Awesome!
Tests failing because dev was temporarily broken. Merging it ! 🎉 🍺 |
@balloob Thanks for that fix, review and finally merge! 🍺 |
* Adds integration for Plaato Airlock * Updates codeowners and coveragerc * Fixes lint errors * Fixers lint check error * Removed sv translation file * Adds en translation file * Sets config flow to true in manifest * Moves config flow and domain to seperate files * Fixes lint errors * Runs hassfest to regenerate config_flows.py * Adds should poll property and fixes for loop * Only log a warning when webhook data was broken * Fixes static test failure * Moves state update from async_update to state prop * Unsubscribes the dispatch signal listener * Update sensor.py
Description:
Adds a new integration for the Plaato Airlock. Plaato Airlock is a tool for beer brewers that wants a unique insight in the fermentation process. It will create sensors for the data that is pushed to a webhook from the airlock.
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#9398
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:
requirements
in the manifest (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.