Add current_humidity attribute to tuya (de)humidifiers (#94953)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>pull/94944/head^2
parent
30453f6982
commit
c47543c9dd
|
@ -28,6 +28,7 @@ class TuyaHumidifierEntityDescription(HumidifierEntityDescription):
|
|||
# DPCode, to use. If None, the key will be used as DPCode
|
||||
dpcode: DPCode | tuple[DPCode, ...] | None = None
|
||||
|
||||
current_humidity: DPCode | None = None
|
||||
humidity: DPCode | None = None
|
||||
|
||||
|
||||
|
@ -37,6 +38,7 @@ HUMIDIFIERS: dict[str, TuyaHumidifierEntityDescription] = {
|
|||
"cs": TuyaHumidifierEntityDescription(
|
||||
key=DPCode.SWITCH,
|
||||
dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
|
||||
current_humidity=DPCode.HUMIDITY_INDOOR,
|
||||
humidity=DPCode.DEHUMIDITY_SET_VALUE,
|
||||
device_class=HumidifierDeviceClass.DEHUMIDIFIER,
|
||||
),
|
||||
|
@ -45,6 +47,7 @@ HUMIDIFIERS: dict[str, TuyaHumidifierEntityDescription] = {
|
|||
"jsq": TuyaHumidifierEntityDescription(
|
||||
key=DPCode.SWITCH,
|
||||
dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
|
||||
current_humidity=DPCode.HUMIDITY_CURRENT,
|
||||
humidity=DPCode.HUMIDITY_SET,
|
||||
device_class=HumidifierDeviceClass.HUMIDIFIER,
|
||||
),
|
||||
|
@ -79,6 +82,7 @@ async def async_setup_entry(
|
|||
class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
|
||||
"""Tuya (de)humidifier Device."""
|
||||
|
||||
_current_humidity: IntegerTypeData | None = None
|
||||
_set_humidity: IntegerTypeData | None = None
|
||||
_switch_dpcode: DPCode | None = None
|
||||
entity_description: TuyaHumidifierEntityDescription
|
||||
|
@ -89,7 +93,7 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
|
|||
device_manager: TuyaDeviceManager,
|
||||
description: TuyaHumidifierEntityDescription,
|
||||
) -> None:
|
||||
"""Init Tuya (de)humidier."""
|
||||
"""Init Tuya (de)humidifier."""
|
||||
super().__init__(device, device_manager)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{super().unique_id}{description.key}"
|
||||
|
@ -107,6 +111,13 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
|
|||
self._attr_min_humidity = int(int_type.min_scaled)
|
||||
self._attr_max_humidity = int(int_type.max_scaled)
|
||||
|
||||
# Determine current humidity DPCode
|
||||
if int_type := self.find_dpcode(
|
||||
description.current_humidity,
|
||||
dptype=DPType.INTEGER,
|
||||
):
|
||||
self._current_humidity = int_type
|
||||
|
||||
# Determine mode support and provided modes
|
||||
if enum_type := self.find_dpcode(
|
||||
DPCode.MODE, dptype=DPType.ENUM, prefer_function=True
|
||||
|
@ -138,6 +149,19 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
|
|||
|
||||
return round(self._set_humidity.scale_value(humidity))
|
||||
|
||||
@property
|
||||
def current_humidity(self) -> int | None:
|
||||
"""Return the current humidity."""
|
||||
if self._current_humidity is None:
|
||||
return None
|
||||
|
||||
if (
|
||||
current_humidity := self.device.status.get(self._current_humidity.dpcode)
|
||||
) is None:
|
||||
return None
|
||||
|
||||
return round(self._current_humidity.scale_value(current_humidity))
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
self._send_command([{"code": self._switch_dpcode, "value": True}])
|
||||
|
|
Loading…
Reference in New Issue