Browse Source

humidifier: support action property

Issue #2364
Jason Rumney 1 year ago
parent
commit
33ee957019

+ 1 - 0
custom_components/tuya_local/devices/README.md

@@ -647,6 +647,7 @@ Humidifer can also cover dehumidifiers (use class to specify which).
 - **mode** (optional, mapping of strings): a dp to control preset modes of the device
 - **humidity** (optional, number): a dp to control the target humidity of the device
 - **current_humidity** (optional, number): a dp to report the current humidity measured by the device
+- **action** (optional, string): a dp to report the current action the device is performing. Valid actions are `humidifying`, `drying`, `idle` and `off`
 
 ### `lawn_mower`
 - **activity** (required, string): a dp to report the current activity of the mower. Valid activities are `mowing`, `paused`, `docked`, `error`, `returning` (from LawnMowerActivities in https://github.com/home-assistant/core/blob/dev/homeassistant/components/lawn_mower/const.py). Any additional activities should be mapped to one of those, and exposed through an extra attribute or sensor entity that shows all the statuses that the mower is reporting.

+ 20 - 0
custom_components/tuya_local/humidifier.py

@@ -5,6 +5,7 @@ Setup for different kinds of Tuya humidifier devices
 import logging
 
 from homeassistant.components.humidifier import (
+    HumidifierAction,
     HumidifierDeviceClass,
     HumidifierEntity,
     HumidifierEntityFeature,
@@ -49,6 +50,7 @@ class TuyaLocalHumidifier(TuyaLocalEntity, HumidifierEntity):
         self._humidity_dp = dps_map.pop("humidity", None)
         self._mode_dp = dps_map.pop("mode", None)
         self._switch_dp = dps_map.pop("switch", None)
+        self._action_dp = dps_map.pop("action", None)
         self._init_end(dps_map)
 
         self._support_flags = HumidifierEntityFeature(0)
@@ -77,6 +79,24 @@ class TuyaLocalHumidifier(TuyaLocalEntity, HumidifierEntity):
             return self.available
         return self._switch_dp.get_value(self._device)
 
+    @property
+    def action(self):
+        """Return the current action."""
+        if self._action_dp:
+            if not self.is_on:
+                return HumidifierAction.OFF
+
+            action = self._action_dp.get_value(self._device)
+            try:
+                return HumidifierAction(action) if action else None
+            except ValueError:
+                _LOGGER.warning(
+                    "%s/%s: Unrecognised action %s ignored",
+                    self._config._device.config,
+                    self.name or "humidifier",
+                    action,
+                )
+
     async def async_turn_on(self, **kwargs):
         """Turn the switch on"""
         await self._switch_dp.async_set_value(self._device, True)