HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
49 stars 9 forks source link

Add `after_dependencies` #97

Closed nagyrobi closed 1 year ago

nagyrobi commented 2 years ago

after_dependencies postpones the loading of the custom component until loading of the integrations specified here finishes first. This is needed in order to avoid template errors generated by openHASP config at startup, due to entities being still unavailable. openHASP should load among the last ones.

dgomes commented 2 years ago

This will not always work...

This is about integration dependencies not domain dependencies. This will only work for entities still under the domain integration (which are fewer on each release as we move them into their own integrations).

nagyrobi commented 2 years ago

Most critical ones are climate, media_player and weather. These are big things and can take long till they load.

dgomes commented 2 years ago

those are domains.... example: sonos media_player can start afterwards with that configuration... also: you can't (at this moment) list ALL integrations in after_dependencies

nagyrobi commented 2 years ago

I see. HA needs a way to set a kind priority when loading integrations

fvanroie commented 2 years ago

Isn't there an event you can subscribe to that indicates when ALL domains and integrations are loaded and HA is ready. Maybe the processing of the templates needs to be deferred until HA is that ready state...

dgomes commented 2 years ago

what is ready :) ?

At that point in time openHASP is not ready yet ... meaning such event can't be sent... this is a tricky race condition, all integrations can wait for everyone, hence no one loads...

dgomes commented 2 years ago

and btw... this only influences python imports... not actual entity availability

nagyrobi commented 2 years ago

I would create a special template sensor containing all my entities which can affect negatively openHASP when they are unavailable. When that shows green, let openHASP go...

dgomes commented 2 years ago

sure you want to block everything in case 1 entity is unavailable ?

nagyrobi commented 2 years ago

Well it would be better indeed if we could make the templates more robust. Unfortunately the entire template is evaluated, despite I put an if condition around it to check for the inner entity availability...