Skip to content

Commit 1389dbc

Browse files
committed
Add refrigerator filter percentage sensors (FR #764)
1 parent 6a1c984 commit 1389dbc

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

custom_components/smartthinq_sensors/sensor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
DeviceType,
6363
MicroWaveFeatures,
6464
RangeFeatures,
65+
RefrigeratorFeatures,
6566
WashDeviceFeatures,
6667
WaterHeaterFeatures,
6768
)
@@ -203,6 +204,20 @@ class ThinQSensorEntityDescription(SensorEntityDescription):
203204
unit_fn=lambda x: x.temp_unit,
204205
value_fn=lambda x: x.temp_freezer,
205206
),
207+
ThinQSensorEntityDescription(
208+
key=RefrigeratorFeatures.FRESHAIRFILTER_REMAIN_PERC,
209+
name="Fresh air filter remaining",
210+
icon="mdi:air-filter",
211+
state_class=SensorStateClass.MEASUREMENT,
212+
native_unit_of_measurement=PERCENTAGE,
213+
),
214+
ThinQSensorEntityDescription(
215+
key=RefrigeratorFeatures.WATERFILTER_REMAIN_PERC,
216+
name="Water filter remaining",
217+
icon="mdi:waves",
218+
state_class=SensorStateClass.MEASUREMENT,
219+
native_unit_of_measurement=PERCENTAGE,
220+
),
206221
)
207222
AC_SENSORS: tuple[ThinQSensorEntityDescription, ...] = (
208223
ThinQSensorEntityDescription(

custom_components/smartthinq_sensors/wideq/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ class RefrigeratorFeatures(StrEnum):
105105
EXPRESSMODE = "express_mode"
106106
EXPRESSFRIDGE = "express_fridge"
107107
FRESHAIRFILTER = "fresh_air_filter"
108+
FRESHAIRFILTER_REMAIN_PERC = "fresh_air_filter_remain_perc"
108109
ICEPLUS = "ice_plus"
109110
SMARTSAVINGMODE = "smart_saving_mode"
110111
WATERFILTERUSED_MONTH = "water_filter_used_month"
112+
WATERFILTER_REMAIN_PERC = "water_filter_remain_perc"
111113

112114

113115
class WashDeviceFeatures(StrEnum):

custom_components/smartthinq_sensors/wideq/devices/refrigerator.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@RE_TERM_EXPRESS_FRIDGE_W": "express_cool",
1818
"@RE_TERM_ICE_PLUS_W": "ice_plus",
1919
}
20+
FEATURE_KEY_IGNORE = "##IGNORE##"
2021

2122
REFRTEMPUNIT = {
2223
"F": TemperatureUnit.FAHRENHEIT,
@@ -87,6 +88,8 @@ def _get_feature_info(self, item_key):
8788
return None
8889

8990
def _get_feature_title(self, feature_name, item_key):
91+
if item_key and item_key == FEATURE_KEY_IGNORE:
92+
return feature_name
9093
item_info = self._get_feature_info(item_key)
9194
if not item_info:
9295
return None
@@ -583,6 +586,24 @@ def fresh_air_filter_status(self):
583586
RefrigeratorFeatures.FRESHAIRFILTER, status, True, key
584587
)
585588

589+
@property
590+
def fresh_air_filter_remain_perc(self):
591+
"""Return fresh air filter remain percentage."""
592+
if not self.is_info_v2:
593+
return None
594+
595+
key = "freshAirFilterRemainP"
596+
status = self.to_int_or_none(self.lookup_range(key))
597+
if status is None or status > 100:
598+
return None
599+
600+
return self._update_feature(
601+
RefrigeratorFeatures.FRESHAIRFILTER_REMAIN_PERC,
602+
status,
603+
False,
604+
FEATURE_KEY_IGNORE,
605+
)
606+
586607
@property
587608
def water_filter_used_month(self):
588609
"""Return water filter used months."""
@@ -605,6 +626,24 @@ def water_filter_used_month(self):
605626
RefrigeratorFeatures.WATERFILTERUSED_MONTH, value, False, key
606627
)
607628

629+
@property
630+
def water_filter_remain_perc(self):
631+
"""Return water filter remain percentage."""
632+
if not self.is_info_v2:
633+
return None
634+
635+
key = "waterFilter1RemainP"
636+
status = self.to_int_or_none(self.lookup_range(key))
637+
if status is None or status > 100:
638+
return None
639+
640+
return self._update_feature(
641+
RefrigeratorFeatures.WATERFILTER_REMAIN_PERC,
642+
status,
643+
False,
644+
FEATURE_KEY_IGNORE,
645+
)
646+
608647
@property
609648
def locked_state(self):
610649
"""Return current locked state."""
@@ -626,5 +665,7 @@ def _update_features(self):
626665
self.express_mode_status,
627666
self.smart_saving_mode,
628667
self.fresh_air_filter_status,
668+
self.fresh_air_filter_remain_perc,
629669
self.water_filter_used_month,
670+
self.water_filter_remain_perc,
630671
]

0 commit comments

Comments
 (0)