瀏覽代碼

Replace the whole config instead of just one item.

The config is not modifyable, so try replacing it all like in the migration examples.

Modify protocol swapping logic to ensure timeouts still happen correctly.
Jason Rumney 4 年之前
父節點
當前提交
661c0b6dcb
共有 2 個文件被更改,包括 4 次插入5 次删除
  1. 1 2
      custom_components/tuya_local/__init__.py
  2. 3 3
      custom_components/tuya_local/device.py

+ 1 - 2
custom_components/tuya_local/__init__.py

@@ -59,8 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
         config[CONF_TYPE] = await device.async_inferred_type()
         if config[CONF_TYPE] is None:
             raise ValueError(f"Unable to detect type for device {device.name}")
-        entry.data[CONF_TYPE] = config[CONF_TYPE]
-        entry.options[CONF_TYPE] = config[CONF_TYPE]
+        entry.data = {**config}
 
     if config.get(CONF_CLIMATE, False) is True:
         hass.async_create_task(

+ 3 - 3
custom_components/tuya_local/device.py

@@ -230,12 +230,12 @@ class TuyaLocalDevice(object):
                 break
             except Exception as e:
                 _LOGGER.debug(f"Retrying after exception {e}")
-                if not self._api_protocol_working:
-                    self._rotate_api_protocol_version()
-                elif i + 1 == self._CONNECTION_ATTEMPTS:
+                if i + 1 == self._CONNECTION_ATTEMPTS:
                     self._reset_cached_state()
                     self._api_protocol_working = False
                     _LOGGER.error(error_message)
+                if not self._api_protocol_working:
+                    self._rotate_api_protocol_version()
 
     def _get_cached_state(self):
         cached_state = self._cached_state.copy()