From fd2f5b6b6a7dc8549dcd57f37b7005b73b5e0dc8 Mon Sep 17 00:00:00 2001 From: Henrik Nicolaisen Date: Sat, 9 Nov 2024 21:41:34 +0100 Subject: [PATCH] set units --- custom_components/siku/api_v1.py | 2 +- custom_components/siku/api_v2.py | 9 ++++++++- custom_components/siku/sensor.py | 28 +++++++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/custom_components/siku/api_v1.py b/custom_components/siku/api_v1.py index 4f9a2d1..613a3ab 100644 --- a/custom_components/siku/api_v1.py +++ b/custom_components/siku/api_v1.py @@ -539,7 +539,7 @@ async def _format_response(self, data: dict) -> dict: "mode": data["operation_mode"], "humidity": int(data["humidity_level"]), "alarm": bool(data["alarm_status"] == NoYes.YES), - "filter_timer": int(data["timer_countdown"]), + "timer_countdown": int(data["timer_countdown"]), "boost": bool( data["boost_mode_after_sensor"] == NoYesYes.YES or data["boost_mode_after_sensor"] == NoYesYes.YES2 diff --git a/custom_components/siku/api_v2.py b/custom_components/siku/api_v2.py index c87b2e4..35e706b 100644 --- a/custom_components/siku/api_v2.py +++ b/custom_components/siku/api_v2.py @@ -39,6 +39,7 @@ COMMAND_DEVICE_TYPE = "B9" COMMAND_BOOST = "06" COMMAND_MODE = "07" +COMMAND_TIMER_COUNTDOWN = "11" COMMAND_CURRENT_HUMIDITY = "25" COMMAND_MANUAL_SPEED = "44" COMMAND_FAN1RPM = "4A" @@ -105,6 +106,7 @@ async def status(self) -> dict: COMMAND_DIRECTION, COMMAND_BOOST, COMMAND_MODE, + COMMAND_TIMER_COUNTDOWN, COMMAND_CURRENT_HUMIDITY, COMMAND_FAN1RPM, COMMAND_FILTER_TIMER, @@ -325,6 +327,10 @@ async def _translate_response(self, data: dict) -> dict: firmware = f"{int(data[COMMAND_READ_FIRMWARE_VERSION][0], 16)}.{int(data[COMMAND_READ_FIRMWARE_VERSION][1], 16)}" except KeyError: firmware = None + try: + timer_countdown = int(data[COMMAND_TIMER_COUNTDOWN], 16) + except KeyError: + timer_countdown = 0 return { "is_on": is_on, "speed": speed, @@ -339,7 +345,8 @@ async def _translate_response(self, data: dict) -> dict: "humidity": humidity, "rpm": rpm, "firmware": firmware, - "filter_timer": filter_timer, + "filter_timer_days": filter_timer, + "timer_countdown": timer_countdown, "alarm": alarm, "version": "2", } diff --git a/custom_components/siku/sensor.py b/custom_components/siku/sensor.py index e4a3fd0..fd73bfe 100644 --- a/custom_components/siku/sensor.py +++ b/custom_components/siku/sensor.py @@ -67,44 +67,54 @@ class SikuSensorEntityDescription(SensorEntityDescription): icon="mdi:alarm-light", ), SikuSensorEntityDescription( - key="filter_timer", + key="filter_timer_days", name="Filter timer countdown", icon="mdi:timer", native_unit_of_measurement=UnitOfTime.MINUTES, - suggested_display_precision=2, + suggested_display_precision=0, suggested_unit_of_measurement=UnitOfTime.DAYS, device_class=SensorDeviceClass.DURATION, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.MEASUREMENT, + ), + SikuSensorEntityDescription( + key="timer_countdown", + name="Timer countdown", + icon="mdi:timer", + native_unit_of_measurement=UnitOfTime.SECONDS, + suggested_display_precision=0, + suggested_unit_of_measurement=UnitOfTime.MINUTES, + device_class=SensorDeviceClass.DURATION, + state_class=SensorStateClass.MEASUREMENT, ), SikuSensorEntityDescription( key="boost_mode_timer", name="Boost mode timer", icon="mdi:timer", native_unit_of_measurement=UnitOfTime.MINUTES, - suggested_display_precision=2, + suggested_display_precision=0, suggested_unit_of_measurement=UnitOfTime.DAYS, device_class=SensorDeviceClass.DURATION, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.MEASUREMENT, ), SikuSensorEntityDescription( key="night_mode_timer", name="Sleep mode timer", icon="mdi:timer", native_unit_of_measurement=UnitOfTime.MINUTES, - suggested_display_precision=2, + suggested_display_precision=0, suggested_unit_of_measurement=UnitOfTime.DAYS, device_class=SensorDeviceClass.DURATION, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.MEASUREMENT, ), SikuSensorEntityDescription( key="party_mode_timer", name="Party mode timer", icon="mdi:timer", native_unit_of_measurement=UnitOfTime.MINUTES, - suggested_display_precision=2, + suggested_display_precision=0, suggested_unit_of_measurement=UnitOfTime.DAYS, device_class=SensorDeviceClass.DURATION, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.MEASUREMENT, ), SikuSensorEntityDescription( key="boost",