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

Fan: add additional percentage and preset parameters to async_turn_on

Some time ago HA quietly added a fan specific turn_on method that takes
additional parameters.  In 2023.12 they have quietly broken the fallback
to the standard ToggleEntity turn_on that allowed this integration to keep
functioning.

This change is just to quickly resolve the errors that HA 2023.12
upgrade has caused for fan entities, it does not do anything with the
percentage and preset_mode parameters, that will need to be done in the
next release.

Issue #1380 (from discussion #1379)
Jason Rumney 2 лет назад
Родитель
Сommit
4e0ab2184f
1 измененных файлов с 11 добавлено и 4 удалено
  1. 11 4
      custom_components/tuya_local/fan.py

+ 11 - 4
custom_components/tuya_local/fan.py

@@ -2,6 +2,7 @@
 Setup for different kinds of Tuya fan devices
 Setup for different kinds of Tuya fan devices
 """
 """
 import logging
 import logging
+from typing import Any
 
 
 from homeassistant.components.fan import FanEntity, FanEntityFeature
 from homeassistant.components.fan import FanEntity, FanEntityFeature
 
 
@@ -66,11 +67,17 @@ class TuyaLocalFan(TuyaLocalEntity, FanEntity):
             return self.available
             return self.available
         return self._switch_dps.get_value(self._device)
         return self._switch_dps.get_value(self._device)
 
 
-    async def async_turn_on(self, **kwargs):
+    async def async_turn_on(
+            self,
+            percentage: int | None = None,
+            preset_mode: str | None = None,
+            **kwargs: Any,
+    ):
         """Turn the switch on"""
         """Turn the switch on"""
-        if self._switch_dps is None:
-            raise NotImplementedError()
-        await self._switch_dps.async_set_value(self._device, True)
+        if self._switch_dps:
+            await self._switch_dps.async_set_value(self._device, True)
+        # TODO: handle percentage and preset_mode parameters, and potentially
+        # other kwargs.
 
 
     async def async_turn_off(self, **kwargs):
     async def async_turn_off(self, **kwargs):
         """Turn the switch off"""
         """Turn the switch off"""