Technique for minimizing schedule_update_ha_state()

I have an asyncio integration. It has a manager that is pulling incoming messages and then executing registered callbacks on HA entities (climate, sensor); and in turn those entities call schedule_update_ha_state(). Later on HA will get the current state from the entity, This all works fine.

However, when multiple messages arrive quickly the callbacks may get executed multiple times which causes HA to have several updates for the same entity in its queue. While this works fine, it is inefficient. Hence I’m looking for advice or examples on how to do this.

The approach I’d like to take is to have an “update_scheduled” flag on the entity. When the callback executes it would check this flag to determine if it should schedule and update, Later on when HA does the update the entity would clear the flag, it’s this last part that I don’t know the best way to do.

Interested on this. In my case, incoming messages are coming too fast and DataUpdateCoordinator are firing callbacks to update entities and some are missed.

Yes, it would be good to have a queue that updates go into, such that the HA state machine will process every update.

The problem we have is signaling there is an update and the delay in HA reading the entity. I believe it works like this as it was originally designed as a poll based system.

I believe this is an architecture issue.