From fb09c2e5598ecf4f946f331e92764f1b7148a5f3 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Wed, 12 Jul 2023 00:20:35 +0200 Subject: [PATCH] Improve hood controls --- README.md | 5 ++--- custom_components/hon/button.py | 14 -------------- custom_components/hon/fan.py | 15 ++++++++++----- custom_components/hon/light.py | 12 +++++++++--- custom_components/hon/switch.py | 14 ++++++++++++++ custom_components/hon/translations/cs.json | 3 +++ custom_components/hon/translations/de.json | 3 +++ custom_components/hon/translations/el.json | 3 +++ custom_components/hon/translations/en.json | 3 +++ custom_components/hon/translations/es.json | 3 +++ custom_components/hon/translations/fr.json | 3 +++ custom_components/hon/translations/he.json | 3 +++ custom_components/hon/translations/hr.json | 3 +++ custom_components/hon/translations/it.json | 3 +++ custom_components/hon/translations/nl.json | 3 +++ custom_components/hon/translations/pl.json | 3 +++ custom_components/hon/translations/pt.json | 3 +++ custom_components/hon/translations/ro.json | 3 +++ custom_components/hon/translations/ru.json | 3 +++ custom_components/hon/translations/sk.json | 3 +++ custom_components/hon/translations/sl.json | 3 +++ custom_components/hon/translations/sr.json | 3 +++ custom_components/hon/translations/tr.json | 3 +++ custom_components/hon/translations/zh.json | 3 +++ scripts/translation_keys.py | 1 + 25 files changed, 93 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6021225..1c55734 100644 --- a/README.md +++ b/README.md @@ -247,9 +247,8 @@ For every device exists a button under diagnostics which can be used to log all #### Controls | Name | Icon | Entity | Key | | --- | --- | --- | --- | -| Light status | | `light` | `startProgram.lightStatus` | -| Start Program | `hvac` | `button` | `startProgram` | -| Stop Program | `hvac-off` | `button` | `stopProgram` | +| Hood | `hvac` | `switch` | `startProgram` / `stopProgram` | +| Light status | | `light` | `settings.lightStatus` | | Wind Speed | | `fan` | `settings.windSpeed` | #### Sensors | Name | Icon | Entity | Key | diff --git a/custom_components/hon/button.py b/custom_components/hon/button.py index 9adb0b8..94c748f 100644 --- a/custom_components/hon/button.py +++ b/custom_components/hon/button.py @@ -35,20 +35,6 @@ BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = { translation_key="stop_program", ), ), - "HO": ( - ButtonEntityDescription( - key="startProgram", - name="Start Program", - icon="mdi:hvac", - translation_key="start_program", - ), - ButtonEntityDescription( - key="stopProgram", - name="Stop Program", - icon="mdi:hvac-off", - translation_key="stop_program", - ), - ), } diff --git a/custom_components/hon/fan.py b/custom_components/hon/fan.py index 35f3536..f0eb550 100644 --- a/custom_components/hon/fan.py +++ b/custom_components/hon/fan.py @@ -63,10 +63,6 @@ class HonFanEntity(HonEntity, FanEntity): def __init__(self, hass, entry, device: HonAppliance, description) -> None: self._attr_supported_features = FanEntityFeature.SET_SPEED self._wind_speed: HonParameterRange = device.settings.get(description.key) - self._speed_range = ( - int(self._wind_speed.values[1]), - int(self._wind_speed.values[-1]), - ) self._command, self._parameter = description.key.split(".") super().__init__(hass, entry, device, description) @@ -118,6 +114,15 @@ class HonFanEntity(HonEntity, FanEntity): @callback def _handle_coordinator_update(self, update=True) -> None: self._wind_speed = self._device.settings.get(self.entity_description.key) - self._attr_percentage = self.percentage + if len(self._wind_speed.values) > 1: + self._speed_range = ( + int(self._wind_speed.values[1]), + int(self._wind_speed.values[-1]), + ) + self._attr_percentage = self.percentage if update: self.async_write_ha_state() + + @property + def available(self) -> bool: + return super().available and len(self._wind_speed.values) > 1 diff --git a/custom_components/hon/light.py b/custom_components/hon/light.py index 7e8633f..3e36017 100644 --- a/custom_components/hon/light.py +++ b/custom_components/hon/light.py @@ -28,7 +28,7 @@ LIGHTS = { ), "HO": ( LightEntityDescription( - key="startProgram.lightStatus", + key="settings.lightStatus", name="Light status", translation_key="light", ), @@ -76,8 +76,7 @@ class HonLightEntity(HonEntity, LightEntity): @property def is_on(self) -> bool: """Return true if light is on.""" - light = self._device.settings.get(self.entity_description.key) - return light.value != light.min + return self._device.get(self.entity_description.key.split(".")[-1]) > 0 async def async_turn_on(self, **kwargs: Any) -> None: """Turn on or control the light.""" @@ -120,3 +119,10 @@ class HonLightEntity(HonEntity, LightEntity): self._attr_brightness = self.brightness if update: self.async_write_ha_state() + + @property + def available(self) -> bool: + return ( + super().available + and len(self._device.settings.get(self.entity_description.key).values) > 1 + ) diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index e96a681..9ed81fb 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -337,6 +337,16 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { translation_key="holiday_mode", ), ), + "HO": ( + HonControlSwitchEntityDescription( + key="onOffStatus", + name="Hood", + icon="mdi:hvac", + turn_on_key="startProgram", + turn_off_key="stopProgram", + translation_key="hood", + ), + ), "AP": ( HonSwitchEntityDescription( key="touchToneStatus", @@ -438,11 +448,15 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity): return self._device.get(self.entity_description.key, False) async def async_turn_on(self, **kwargs: Any) -> None: + self._device.sync_command(self.entity_description.turn_on_key, "settings") + await self.coordinator.async_refresh() await self._device.commands[self.entity_description.turn_on_key].send() self._device.attributes[self.entity_description.key] = True self.async_write_ha_state() async def async_turn_off(self, **kwargs: Any) -> None: + self._device.sync_command(self.entity_description.turn_off_key, "settings") + await self.coordinator.async_refresh() await self._device.commands[self.entity_description.turn_off_key].send() self._device.attributes[self.entity_description.key] = False self.async_write_ha_state() diff --git a/custom_components/hon/translations/cs.json b/custom_components/hon/translations/cs.json index 84a2f6f..9e89083 100644 --- a/custom_components/hon/translations/cs.json +++ b/custom_components/hon/translations/cs.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygienický plus" + }, + "hood": { + "name": "Odsavač par" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/de.json b/custom_components/hon/translations/de.json index 3cdbb5e..6f7bdc8 100644 --- a/custom_components/hon/translations/de.json +++ b/custom_components/hon/translations/de.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiene plus" + }, + "hood": { + "name": "Abzugshaube" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/el.json b/custom_components/hon/translations/el.json index 637dfc1..4ddb68e 100644 --- a/custom_components/hon/translations/el.json +++ b/custom_components/hon/translations/el.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiene plus" + }, + "hood": { + "name": "Απορροφητήρας" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/en.json b/custom_components/hon/translations/en.json index 79e3137..84880a5 100644 --- a/custom_components/hon/translations/en.json +++ b/custom_components/hon/translations/en.json @@ -1814,6 +1814,9 @@ }, "hygiene": { "name": "Hygiene plus" + }, + "hood": { + "name": "Hood" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/es.json b/custom_components/hon/translations/es.json index 7c6efe7..832d79b 100644 --- a/custom_components/hon/translations/es.json +++ b/custom_components/hon/translations/es.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Higiene extra" + }, + "hood": { + "name": "Campana extractora" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/fr.json b/custom_components/hon/translations/fr.json index cab5c7b..eaca2a5 100644 --- a/custom_components/hon/translations/fr.json +++ b/custom_components/hon/translations/fr.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiène plus" + }, + "hood": { + "name": "Hotte" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/he.json b/custom_components/hon/translations/he.json index 5c1c6b6..e69135e 100644 --- a/custom_components/hon/translations/he.json +++ b/custom_components/hon/translations/he.json @@ -908,6 +908,9 @@ }, "hygiene": { "name": "היגיינה פלוס" + }, + "hood": { + "name": "Hood" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/hr.json b/custom_components/hon/translations/hr.json index daab723..cd5cdb2 100644 --- a/custom_components/hon/translations/hr.json +++ b/custom_components/hon/translations/hr.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiene Plus" + }, + "hood": { + "name": "Napa" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/it.json b/custom_components/hon/translations/it.json index dd88f3b..9eaac1c 100644 --- a/custom_components/hon/translations/it.json +++ b/custom_components/hon/translations/it.json @@ -1792,6 +1792,9 @@ }, "hygiene": { "name": "Hygiene plus" + }, + "hood": { + "name": "Cappa" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/nl.json b/custom_components/hon/translations/nl.json index de3333e..86f8fa3 100644 --- a/custom_components/hon/translations/nl.json +++ b/custom_components/hon/translations/nl.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiëne plus" + }, + "hood": { + "name": "Afzuigkap" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/pl.json b/custom_components/hon/translations/pl.json index fcf3b07..d5b61ff 100644 --- a/custom_components/hon/translations/pl.json +++ b/custom_components/hon/translations/pl.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Higiena plus" + }, + "hood": { + "name": "Okap" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/pt.json b/custom_components/hon/translations/pt.json index 5a82001..c94e44a 100644 --- a/custom_components/hon/translations/pt.json +++ b/custom_components/hon/translations/pt.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Higiene mais" + }, + "hood": { + "name": "Exaustor" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/ro.json b/custom_components/hon/translations/ro.json index 7bd066c..e830f5b 100644 --- a/custom_components/hon/translations/ro.json +++ b/custom_components/hon/translations/ro.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Igienizare plus" + }, + "hood": { + "name": "Hotă" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/ru.json b/custom_components/hon/translations/ru.json index 177a326..8def776 100644 --- a/custom_components/hon/translations/ru.json +++ b/custom_components/hon/translations/ru.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Гигиена плюс" + }, + "hood": { + "name": "Вытяжка" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/sk.json b/custom_components/hon/translations/sk.json index ba178c1..5219836 100644 --- a/custom_components/hon/translations/sk.json +++ b/custom_components/hon/translations/sk.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiena plus" + }, + "hood": { + "name": "Digestor" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/sl.json b/custom_components/hon/translations/sl.json index 419fd0d..abc6124 100644 --- a/custom_components/hon/translations/sl.json +++ b/custom_components/hon/translations/sl.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Higiena plus" + }, + "hood": { + "name": "Kuhinjska napa" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/sr.json b/custom_components/hon/translations/sr.json index 152af7c..02687e8 100644 --- a/custom_components/hon/translations/sr.json +++ b/custom_components/hon/translations/sr.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Higijenski plus" + }, + "hood": { + "name": "Aspirator" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/tr.json b/custom_components/hon/translations/tr.json index b469240..2acfc66 100644 --- a/custom_components/hon/translations/tr.json +++ b/custom_components/hon/translations/tr.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "Hygiene plus" + }, + "hood": { + "name": "Davlumbaz" } }, "binary_sensor": { diff --git a/custom_components/hon/translations/zh.json b/custom_components/hon/translations/zh.json index eefa1fe..fd3c75e 100644 --- a/custom_components/hon/translations/zh.json +++ b/custom_components/hon/translations/zh.json @@ -1787,6 +1787,9 @@ }, "hygiene": { "name": "卫生增强" + }, + "hood": { + "name": "机盖" } }, "binary_sensor": { diff --git a/scripts/translation_keys.py b/scripts/translation_keys.py index dff1c4d..46a4ae6 100644 --- a/scripts/translation_keys.py +++ b/scripts/translation_keys.py @@ -241,6 +241,7 @@ NAMES = { "refrigerator": "REF.NAME", "touch_tone": "AP.FOOTER_MENU_MORE.TOUCH_TONE_VOLUME", "hygiene": "WASHING_CMD&CTRL.PROGRAM_CYCLE_DETAIL_OTHER_OPTIONS.HYGIENE", + "hood": "GLOBALS.APPLIANCES_NAME.HO", }, "binary_sensor": { "door_lock": "WASHING_CMD&CTRL.CHECK_UP_RESULTS.DOOR_LOCK",