Sfoglia il codice sorgente

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 anni fa
parent
commit
661c0b6dcb

+ 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()
         config[CONF_TYPE] = await device.async_inferred_type()
         if config[CONF_TYPE] is None:
         if config[CONF_TYPE] is None:
             raise ValueError(f"Unable to detect type for device {device.name}")
             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:
     if config.get(CONF_CLIMATE, False) is True:
         hass.async_create_task(
         hass.async_create_task(

+ 3 - 3
custom_components/tuya_local/device.py

@@ -230,12 +230,12 @@ class TuyaLocalDevice(object):
                 break
                 break
             except Exception as e:
             except Exception as e:
                 _LOGGER.debug(f"Retrying after exception {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._reset_cached_state()
                     self._api_protocol_working = False
                     self._api_protocol_working = False
                     _LOGGER.error(error_message)
                     _LOGGER.error(error_message)
+                if not self._api_protocol_working:
+                    self._rotate_api_protocol_version()
 
 
     def _get_cached_state(self):
     def _get_cached_state(self):
         cached_state = self._cached_state.copy()
         cached_state = self._cached_state.copy()