Hello Home Assistant pros, I am the developer of a custom component called Magic Areas which relies on your existing entities to do its thing.
One of the features creates groups for sensors, so if you have 3 motion sensors in an area it will create a group with those 3 motion sensors as an “aggregate” sensor. That is one example of why Magic Areas needs to have all your entities loaded already when it starts up.
For this, I accomplish that by having this on my async_setup_entry
code:
# Wait for Hass to have started before setting up.
if hass.is_running:
hass.create_task(_async_setup_integration())
else:
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STARTED, _async_setup_integration
)
There’s also the concept of meta areas, like “Global” or “Exterior” which depends on entities of the other general Magic Areas.
I’m working on an update where those meta-areas gets automatically reloaded if one of the underlying entries are reloaded, to pick up any new configuration.
Using my current code of waiting for home assistant to start, whenever the reload is triggered, Home Assistant complains that the platforms are already loaded (looks like my waiting for home assistant to initialize confuses the stack somehow).
This is solved by skipping this block and just calling
await _async_setup_integration()
Instead. But evidently this creates the race condition where not everything is loaded.
I’ve added a bunch of platforms to the after_dependencies
section on my manifest but that seems to have zero effect, as this only guarantees they’re loaded but not that all the entities have been created yet on those platforms.
Before I start making some horrible war crimes on code, I wanted to get your opinion so I can implement this right. Looking forward to learning from you guys, thanks in advance! Let me know if you need any other information on my side.
Current reload logic: hass-magic_areas/custom_components/magic_areas/base/magic.py at hotfix/reload-meta-area-on-new-area-load · jseidl/hass-magic_areas · GitHub