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

fix (light): turn off by effect should not require a read-only switch

Allow fallback to off by effect dp when there is no switch dp at all.
Jason Rumney 2 месяцев назад
Родитель
Сommit
96a21471d7
1 измененных файлов с 7 добавлено и 15 удалено
  1. 7 15
      custom_components/tuya_local/light.py

+ 7 - 15
custom_components/tuya_local/light.py

@@ -541,27 +541,19 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
             await self._device.async_set_properties(settings)
 
     async def async_turn_off(self):
-        if self._switch_dps:
-            if (
-                self._switch_dps.readonly
-                and self._effect_dps
-                and "off" in self._effect_dps.values(self._device)
-            ):
-                # Special case for motion sensor lights with readonly switch
-                # that have tristate switch available as effect
-                _LOGGER.info(
-                    "%s turning light off using effect", self._config.config_id
-                )
-                await self._effect_dps.async_set_value(self._device, "off")
-            else:
-                _LOGGER.info("%s turning light off", self._config.config_id)
-                await self._switch_dps.async_set_value(self._device, False)
+        if self._switch_dps and not self._switch_dps.readonly:
+            _LOGGER.info("%s turning light off", self._config.config_id)
+            await self._switch_dps.async_set_value(self._device, False)
         elif self._brightness_dps:
             _LOGGER.info(
                 "%s turning light off by setting brightness to 0",
                 self._config.config_id,
             )
             await self._brightness_dps.async_set_value(self._device, 0)
+        elif self._effect_dps and "off" in self._effect_dps.values(self._device):
+            # off by effect
+            _LOGGER.info("%s turning light off using effect", self._config.config_id)
+            await self._effect_dps.async_set_value(self._device, "off")
         else:
             raise NotImplementedError()