Просмотр исходного кода

Config flow: test connection in an async_executor_job.

Auto IP address setting is broken since HA started forcing an error
for sleeping in the event loop. Other locations were changed to also
avoid other warnings about I/O on the event loop, but this one was not
updated.

Discussion #2244
Jason Rumney 1 год назад
Родитель
Сommit
5ce4a3f640
1 измененных файлов с 20 добавлено и 8 удалено
  1. 20 8
      custom_components/tuya_local/config_flow.py

+ 20 - 8
custom_components/tuya_local/config_flow.py

@@ -595,6 +595,23 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
         )
         )
 
 
 
 
+def create_test_device(hass: HomeAssistant, config: dict):
+    """Set up a tuya device based on passed in config."""
+    subdevice_id = config.get(CONF_DEVICE_CID)
+    device = TuyaLocalDevice(
+        "Test",
+        config[CONF_DEVICE_ID],
+        config[CONF_HOST],
+        config[CONF_LOCAL_KEY],
+        config[CONF_PROTOCOL_VERSION],
+        subdevice_id,
+        hass,
+        True,
+    )
+
+    return device
+
+
 async def async_test_connection(config: dict, hass: HomeAssistant):
 async def async_test_connection(config: dict, hass: HomeAssistant):
     domain_data = hass.data.get(DOMAIN)
     domain_data = hass.data.get(DOMAIN)
     existing = domain_data.get(get_device_id(config)) if domain_data else None
     existing = domain_data.get(get_device_id(config)) if domain_data else None
@@ -605,15 +622,10 @@ async def async_test_connection(config: dict, hass: HomeAssistant):
 
 
     try:
     try:
         subdevice_id = config.get(CONF_DEVICE_CID)
         subdevice_id = config.get(CONF_DEVICE_CID)
-        device = TuyaLocalDevice(
-            "Test",
-            config[CONF_DEVICE_ID],
-            config[CONF_HOST],
-            config[CONF_LOCAL_KEY],
-            config[CONF_PROTOCOL_VERSION],
-            subdevice_id,
+        device = await hass.async_add_executor_job(
+            create_test_device,
             hass,
             hass,
-            True,
+            config,
         )
         )
         await device.async_refresh()
         await device.async_refresh()
         retval = device if device.has_returned_state else None
         retval = device if device.has_returned_state else None