Explorar el Código

fix(climate): don't lock before calling other functions that lock

Python locks are non-reentrant so attempting to lock the same lock in the same thread
causes a deadlock.

Issue #5131, likely also #5129
Jason Rumney hace 2 semanas
padre
commit
4b38528ad2
Se han modificado 1 ficheros con 26 adiciones y 27 borrados
  1. 26 27
      custom_components/tuya_local/climate.py

+ 26 - 27
custom_components/tuya_local/climate.py

@@ -244,33 +244,32 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
 
     async def async_set_temperature(self, **kwargs):
         """Set new target temperature."""
-        async with self._device.set_lock:
-            if kwargs.get(ATTR_PRESET_MODE) is not None:
-                _LOGGER.info(
-                    "%s setting temperature: setting preset mode to %s",
-                    self._config.config_id,
-                    kwargs.get(ATTR_PRESET_MODE),
-                )
-                await self.async_set_preset_mode(kwargs.get(ATTR_PRESET_MODE))
-            if kwargs.get(ATTR_TEMPERATURE) is not None:
-                _LOGGER.info(
-                    "%s setting temperature to %s",
-                    self._config.config_id,
-                    kwargs.get(ATTR_TEMPERATURE),
-                )
-                await self.async_set_target_temperature(
-                    kwargs.get(ATTR_TEMPERATURE),
-                )
-            high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
-            low = kwargs.get(ATTR_TARGET_TEMP_LOW)
-            if high is not None or low is not None:
-                _LOGGER.info(
-                    "%s setting temperature range to %s - %s",
-                    self._config.config_id,
-                    low,
-                    high,
-                )
-                await self.async_set_target_temperature_range(low, high)
+        if kwargs.get(ATTR_PRESET_MODE) is not None:
+            _LOGGER.info(
+                "%s setting temperature: setting preset mode to %s",
+                self._config.config_id,
+                kwargs.get(ATTR_PRESET_MODE),
+            )
+            await self.async_set_preset_mode(kwargs.get(ATTR_PRESET_MODE))
+        if kwargs.get(ATTR_TEMPERATURE) is not None:
+            _LOGGER.info(
+                "%s setting temperature to %s",
+                self._config.config_id,
+                kwargs.get(ATTR_TEMPERATURE),
+            )
+            await self.async_set_target_temperature(
+                kwargs.get(ATTR_TEMPERATURE),
+            )
+        high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
+        low = kwargs.get(ATTR_TARGET_TEMP_LOW)
+        if high is not None or low is not None:
+            _LOGGER.info(
+                "%s setting temperature range to %s - %s",
+                self._config.config_id,
+                low,
+                high,
+            )
+            await self.async_set_target_temperature_range(low, high)
 
     async def async_set_target_temperature(self, target_temperature):
         if self._temperature_dps is None: