Updating a whole platform as opposed to entities one by one

The state of all the entities (sensors, switches, thermostats and lights) in my custom platform is fetched with a single API call. Is there a way to prevent HA to call update/async_update on each entity and call it on the platform instead?

In the same situation inside update/async_update I check for entities Id and if it sensor #1 I call platform update (from the hardware). Now I plan to remake - translate a call from entities to platform every time, but inside the platform add a limit on the minimum update interval. If the previous call was just recently - do nothing.

if there is a better solution I will be glad to know.

I actually did something like that on the API side to throttle requests with a threading.Lock().

It worked pretty well until I rewrote the code to be asynchronous and switched from requests to aiohttp. For some reason, it’s hanging and I can’t figure out why.

I don’t know a lot about it, but you should check out the nest component. It uses a “dispatcher” from the central module (__init__.py) to send updates to each of the platforms.

1 Like

Thanks for the pointer!

It looks like I have missed at least one particular page of the documentation (https://developers.home-assistant.io/docs/en/entity_index.html) which should help make the component a lot more efficient;