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.