@@ -30,7 +30,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3030 """Initialize immediately"""
3131 await async_init (hass , entry , auto_area )
3232 else :
33- """Schedule initialization when HA is started"""
33+ """Schedule initialization when HA is started and initialized"""
34+
3435 # https://developers.home-assistant.io/docs/asyncio_working_with_async/#calling-async-functions-from-threads
3536
3637 @callback
@@ -39,10 +40,6 @@ def init(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
3940 async_init (hass , entry , auto_area ), hass .loop
4041 ).result ()
4142
42- LOGGER .info (
43- "😴 Deferring AutoAreas setup by 10 seconds to make sure all entities are ready" )
44- await asyncio .sleep (10 )
45-
4643 hass .bus .async_listen_once (
4744 EVENT_HOMEASSISTANT_STARTED ,
4845 lambda params : init (hass , entry , auto_area )
@@ -51,20 +48,22 @@ def init(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
5148 return True
5249
5350
54- def initialize (hass : HomeAssistant , entry : ConfigEntry , auto_area : AutoArea ):
55- """Initialize area after HA has started."""
56- asyncio .run_coroutine_threadsafe (
57- async_init (hass , entry , auto_area ), hass .loop
58- ).result ()
59-
60-
6151async def async_init (hass : HomeAssistant , entry : ConfigEntry , auto_area : AutoArea ):
6252 """Initialize component."""
63- await auto_area .initialize ()
53+ await asyncio .sleep (5 ) # wait for all area devices to be initialized
54+ await auto_area .async_initialize ()
55+ await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
56+
6457 entry .async_on_unload (entry .add_update_listener (async_reload_entry ))
65- hass .async_create_task (
66- hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
67- )
58+
59+ return True
60+
61+
62+ async def async_reload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> None :
63+ """Reload config entry."""
64+ LOGGER .info ("🔄 Reloading entry %s" , entry )
65+
66+ await hass .config_entries .async_reload (entry .entry_id )
6867
6968
7069async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
@@ -83,12 +82,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
8382 return unloaded
8483
8584
86- async def async_reload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> None :
87- """Reload config entry."""
88- await async_unload_entry (hass , entry )
89- await async_setup_entry (hass , entry )
90-
91-
9285async def async_setup (hass : HomeAssistant , config : ConfigType ) -> bool :
9386 """Check for YAML-config."""
9487
0 commit comments