#I'm trying to understand a bug in an
1 messages ยท Page 1 of 1 (latest)
The update interval is set to 1 day: https://github.com/home-assistant/core/blob/dev/homeassistant/components/recollect_waste/__init__.py#L57
But the sensor https://github.com/home-assistant/core/blob/dev/homeassistant/components/recollect_waste/sensor.py#L77 never updates.
Is the underlying sensor DataUpdateCoordinator having an update interval an issue?
I'm still groking through the docs https://developers.home-assistant.io/docs/integration_fetching_data
I expect not, given the examples in the doc. But the integrations sensors fail to update weekely
Did you already check out if similar integrations write explicitly to the state machine?
I've setting up something to try and reproduce.
This is my first time this deep into an integration so I'm just trying to catch up on docs for the DataUpdateCoordinator.
My assumption is that it somehow isn't running.
But based on your statement I assume you're referring to the fact it's directly writing to the private members: https://github.com/home-assistant/core/blob/dev/homeassistant/components/recollect_waste/sensor.py#L90-L94
Thus likely bypassing some triggers that may update the state properly?
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._async_update_attrs()
super()._handle_coordinator_update()
this is something I have used / seen being used
_handle_coordinator_update() simply does self.async_write_ha_state()
Thanks, I'll look for more patterns.
I'm just re-setting up my devcontainer right now to dig in.
Hopefully can fake a reproduction also
ok yup definitely reproduced this.
Spun up a dev instance, installed the relevant integration, let it setup correctly.
Then I forced the sensors to be back to old data.
But when https://github.com/home-assistant/core/blob/dev/homeassistant/components/recollect_waste/sensor.py#L77-L94 function runs to update said sensors, they don't update.
welp that was it, super()._handle_coordinator_update()
solved it.
๐ TYVM, and I learned a bit more about the internal guts of the system too along the way.
Great! If you don't mind, take a look if there's a nice spot for developer doc update for this ๐
Yeah I cam maybe circle round to that tonight after the kids are asleep.
https://developers.home-assistant.io/docs/integration_fetching_data
The example here does call async_write_ha_state so I'm not sure anything needs to be noted specifically.
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_is_on = self.coordinator.data[self.idx]["state"]
self.async_write_ha_state()
I'm just going to chalk it up to my unfamiliarity of being this far into an integration's and not seeing seeing the forest for the trees.
If you are executing from within an async function and don't need your entity update method called, call Entity.async_write_ha_state(). This is an async callback that will write the state to the state machine within yielding to the event loop.