From 2592ec71032b6315ad59d564d92b8302c0c451fb Mon Sep 17 00:00:00 2001 From: Ankit Mehta <10181117+ankitmehtame@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:50:16 +0800 Subject: [PATCH 1/2] Update dehumidifier water tank to use light status Use `airState.notificationExt` to get water tank status --- .../smartthinq_sensors/wideq/devices/dehumidifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py b/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py index 69adc36f..a8055fd2 100644 --- a/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py +++ b/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py @@ -27,7 +27,7 @@ STATE_PM1 = ["SensorPM1", "airState.quality.PM1"] STATE_PM10 = ["SensorPM10", "airState.quality.PM10"] STATE_PM25 = ["SensorPM2", "airState.quality.PM2"] -STATE_TANK_LIGHT = ["WatertankLight", "airState.miscFuncState.watertankLight"] +STATE_TANK_LIGHT = ["WatertankLight", "airState.notificationExt"] STATE_POWER = [STATE_POWER_V1, "airState.energy.onCurrent"] From bdbdd8f86d15c97a4f716db999b82063dbceac0b Mon Sep 17 00:00:00 2001 From: Ankit Mehta <10181117+ankitmehtame@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:28:33 +0800 Subject: [PATCH 2/2] Dehumidifer water tank full (#1) * Update water tank full sensor Updated to be based on airState.notificationExt and int rather than bool * Add separate field for notification light, defensive code with logging * Updated to lookup value * Improve logging * Always log notification light value * Keep notification light as integer * Make notification light int * Make the notification light bool again * Cleanup sensor, categorize notification light as problem --- .../smartthinq_sensors/binary_sensor.py | 6 ++++ .../smartthinq_sensors/wideq/const.py | 1 + .../wideq/devices/dehumidifier.py | 34 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/custom_components/smartthinq_sensors/binary_sensor.py b/custom_components/smartthinq_sensors/binary_sensor.py index 1888bbd0..37356cb4 100644 --- a/custom_components/smartthinq_sensors/binary_sensor.py +++ b/custom_components/smartthinq_sensors/binary_sensor.py @@ -198,6 +198,12 @@ class ThinQBinarySensorEntityDescription(BinarySensorEntityDescription): key=DehumidifierFeatures.WATER_TANK_FULL, name="Water Tank Full", ), + ThinQBinarySensorEntityDescription( + key=DehumidifierFeatures.NOTIFICATION_LIGHT, + name="Notification Light", + device_class=BinarySensorDeviceClass.PROBLEM, + value_fn=lambda x: x.notification_light, + ), ) BINARY_SENSOR_ENTITIES = { diff --git a/custom_components/smartthinq_sensors/wideq/const.py b/custom_components/smartthinq_sensors/wideq/const.py index 5ff64fd9..15d077b0 100644 --- a/custom_components/smartthinq_sensors/wideq/const.py +++ b/custom_components/smartthinq_sensors/wideq/const.py @@ -80,6 +80,7 @@ class DehumidifierFeatures(StrEnum): HUMIDITY = "humidity" TARGET_HUMIDITY = "target_humidity" WATER_TANK_FULL = "water_tank_full" + NOTIFICATION_LIGHT = "notification_light" class RangeFeatures(StrEnum): diff --git a/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py b/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py index a8055fd2..ff239b03 100644 --- a/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py +++ b/custom_components/smartthinq_sensors/wideq/devices/dehumidifier.py @@ -2,6 +2,8 @@ from __future__ import annotations +import logging + from enum import Enum from ..backports.functools import cached_property @@ -27,7 +29,8 @@ STATE_PM1 = ["SensorPM1", "airState.quality.PM1"] STATE_PM10 = ["SensorPM10", "airState.quality.PM10"] STATE_PM25 = ["SensorPM2", "airState.quality.PM2"] -STATE_TANK_LIGHT = ["WatertankLight", "airState.notificationExt"] +STATE_TANK_LIGHT = ["WatertankLight", "airState.miscFuncState.watertankLight"] +STATE_NOTIFICATION_LIGHT = ["NotificationLight", "airState.notificationExt"] STATE_POWER = [STATE_POWER_V1, "airState.energy.onCurrent"] @@ -44,6 +47,8 @@ ADD_FEAT_POLL_INTERVAL = 300 # 5 minutes +_LOGGER = logging.getLogger(__name__) + class DHumOp(Enum): """Whether a device is on or off.""" @@ -314,9 +319,36 @@ def water_tank_full(self): return None return self._update_feature(DehumidifierFeatures.WATER_TANK_FULL, value) + @property + def notification_light(self) -> bool | None: + """Return notification light status.""" + try: + key = self._get_state_key(STATE_NOTIFICATION_LIGHT) + except: + key = None + _LOGGER.exception("LGE ThinQ dehumidifier - unable to get Notification Light status") + if key is None: + ntf_real_value = None + ntf_light_int_value = None + ntf_light_bool_val = None + else: + ntf_real_value = self.lookup_range(key) + ntf_light_int_value = self.to_int_or_none(ntf_real_value) + if ntf_light_int_value is None: + ntf_light_bool_val = None + _LOGGER.warning(f"LGE ThinQ dehumidifier Notification light is {ntf_real_value}. int {ntf_light_int_value}. bool {ntf_light_bool_val}") + elif ntf_light_int_value > 0: + ntf_light_bool_val = True + else: + ntf_light_bool_val = False + if ntf_light_bool_val is not None: + _LOGGER.debug(f"LGE ThinQ dehumidifier Notification light is {ntf_real_value}. int {ntf_light_int_value}. bool {ntf_light_bool_val}") + return self._update_feature(DehumidifierFeatures.NOTIFICATION_LIGHT, ntf_light_bool_val) + def _update_features(self): _ = [ self.current_humidity, self.target_humidity, self.water_tank_full, + self.notification_light ]