Răsfoiți Sursa

Refactor async_setup_entry.

Use async_forward_entry_setups instead of looping over async_forward_setup_entry separately for each entity type.
Await it instead of spawning a worker thread, per the suggestion on HA developer blog to avoid reloading while the platforms are being setup.

Issue #195
Jason Rumney 3 ani în urmă
părinte
comite
f82d85e8ee
1 a modificat fișierele cu 4 adăugiri și 5 ștergeri
  1. 4 5
      custom_components/tuya_local/__init__.py

+ 4 - 5
custom_components/tuya_local/__init__.py

@@ -151,14 +151,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
         _LOGGER.error(f"Configuration file for {config[CONF_TYPE]} not found.")
         return False
 
-    entities = {}
+    entities = set()
     e = device_conf.primary_entity
-    entities[e.entity] = True
+    entities.add(e.entity)
     for e in device_conf.secondary_entities():
-        entities[e.entity] = True
+        entities.add(e.entity)
 
-    for e in entities:
-        hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, e))
+    await hass.config_entries.async_forward_entry_setups(entry, entities)
 
     entry.add_update_listener(async_update_entry)