#I'm trying to understand a bug in an

1 messages ยท Page 1 of 1 (latest)

deft viper
#

I expect not, given the examples in the doc. But the integrations sensors fail to update weekely

balmy sparrow
#

Did you already check out if similar integrations write explicitly to the state machine?

deft viper
#

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?

balmy sparrow
#
    @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()

deft viper
#

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

deft viper
#

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.

deft viper
balmy sparrow
#

Great! If you don't mind, take a look if there's a nice spot for developer doc update for this ๐Ÿ™‚

deft viper
#

Yeah I cam maybe circle round to that tonight after the kids are asleep.

deft viper
#

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.