Преглед на файлове

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()