1 """Support for Tuya (de)humidifiers."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from tuya_sharing
import CustomerDevice, Manager
10 HumidifierDeviceClass,
12 HumidifierEntityDescription,
13 HumidifierEntityFeature,
19 from .
import TuyaConfigEntry
20 from .const
import TUYA_DISCOVERY_NEW, DPCode, DPType
21 from .entity
import IntegerTypeData, TuyaEntity
24 @dataclass(frozen=True)
26 """Describe an Tuya (de)humidifier entity."""
29 dpcode: DPCode | tuple[DPCode, ...] |
None =
None
31 current_humidity: DPCode |
None =
None
32 humidity: DPCode |
None =
None
35 HUMIDIFIERS: dict[str, TuyaHumidifierEntityDescription] = {
40 dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
41 current_humidity=DPCode.HUMIDITY_INDOOR,
42 humidity=DPCode.DEHUMIDITY_SET_VALUE,
43 device_class=HumidifierDeviceClass.DEHUMIDIFIER,
49 dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
50 current_humidity=DPCode.HUMIDITY_CURRENT,
51 humidity=DPCode.HUMIDITY_SET,
52 device_class=HumidifierDeviceClass.HUMIDIFIER,
58 hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback
60 """Set up Tuya (de)humidifier dynamically through Tuya discovery."""
61 hass_data = entry.runtime_data
65 """Discover and add a discovered Tuya (de)humidifier."""
66 entities: list[TuyaHumidifierEntity] = []
67 for device_id
in device_ids:
68 device = hass_data.manager.device_map[device_id]
69 if description := HUMIDIFIERS.get(device.category):
77 entry.async_on_unload(
83 """Tuya (de)humidifier Device."""
85 _current_humidity: IntegerTypeData |
None =
None
86 _set_humidity: IntegerTypeData |
None =
None
87 _switch_dpcode: DPCode |
None =
None
88 entity_description: TuyaHumidifierEntityDescription
93 device: CustomerDevice,
94 device_manager: Manager,
95 description: TuyaHumidifierEntityDescription,
97 """Init Tuya (de)humidifier."""
98 super().
__init__(device, device_manager)
104 description.dpcode
or DPCode(description.key), prefer_function=
True
109 description.humidity, dptype=DPType.INTEGER, prefer_function=
True
117 description.current_humidity,
118 dptype=DPType.INTEGER,
124 DPCode.MODE, dptype=DPType.ENUM, prefer_function=
True
126 self._attr_supported_features |= HumidifierEntityFeature.MODES
131 """Return the device is on or off."""
138 """Return the current mode."""
139 return self.
devicedevice.status.get(DPCode.MODE)
143 """Return the humidity we try to reach."""
151 return round(self.
_set_humidity_set_humidity.scale_value(humidity))
155 """Return the current humidity."""
164 return round(self.
_current_humidity_current_humidity.scale_value(current_humidity))
167 """Turn the device on."""
171 """Turn the device off."""
175 """Set new target humidity."""
178 "Cannot set humidity, device doesn't provide methods to set it"
185 "value": self.
_set_humidity_set_humidity.scale_value_back(humidity),
191 """Set new target preset mode."""
192 self.
_send_command_send_command([{
"code": DPCode.MODE,
"value": mode}])
None _send_command(self, list[dict[str, Any]] commands)
DPCode|EnumTypeData|IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, DPType|None dptype=None)
IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.INTEGER] dptype)
DPCode|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False)
EnumTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.ENUM] dptype)
None set_humidity(self, int humidity)
None __init__(self, CustomerDevice device, Manager device_manager, TuyaHumidifierEntityDescription description)
int|None current_humidity(self)
def turn_off(self, **kwargs)
def turn_on(self, **kwargs)
int|None target_humidity(self)
ElkSystem|None async_discover_device(HomeAssistant hass, str host)
None async_setup_entry(HomeAssistant hass, TuyaConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)