From dfa5735bc2d6a62a6644437f2d02d53082c5f87f Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 12 Jun 2023 00:20:38 +0200 Subject: [PATCH] Readable internal names for some selects --- README.md | 1 + custom_components/hon/const.py | 2 + custom_components/hon/manifest.json | 2 +- custom_components/hon/select.py | 31 ++++++++------ custom_components/hon/sensor.py | 48 ++++++++++++++-------- 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 | 2 + 25 files changed, 93 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index a52cdaa..e0ac3ea 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ For every device exists a hidden button which can be used to log all infos of yo | Filter Replacement | | `binary_sensor` | `filterChangeStatusLocal` | | In Air Temperature Outdoor | `thermometer` | `sensor` | `tempInAirOutdoor` | | Indoor Temperature | `thermometer` | `sensor` | `tempIndoor` | +| Machine Status | `information` | `sensor` | `machMode` | | Outdoor Temperature | `thermometer` | `sensor` | `tempOutdoor` | | Program | | `select` | `startProgram.program` | | Program | `play` | `sensor` | `programName` | diff --git a/custom_components/hon/const.py b/custom_components/hon/const.py index 3525859..9290eaa 100644 --- a/custom_components/hon/const.py +++ b/custom_components/hon/const.py @@ -128,6 +128,7 @@ TUMBLE_DRYER_PR_PHASE = { } DIRTY_LEVEL = { + "0": "unknown", "1": "little", "2": "normal", "3": "very", @@ -185,4 +186,5 @@ AC_HUMAN_SENSE = { "0": "touch_off", "1": "avoid_touch", "2": "follow_touch", + "3": "unknown", } diff --git a/custom_components/hon/manifest.json b/custom_components/hon/manifest.json index 70e82d3..d39f53b 100644 --- a/custom_components/hon/manifest.json +++ b/custom_components/hon/manifest.json @@ -11,5 +11,5 @@ "requirements": [ "pyhOn==0.13.0" ], - "version": "0.9.0-beta.1" + "version": "0.9.0-beta.2" } diff --git a/custom_components/hon/select.py b/custom_components/hon/select.py index 947db9a..d15f4b3 100644 --- a/custom_components/hon/select.py +++ b/custom_components/hon/select.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging from dataclasses import dataclass +from typing import Dict, List from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry @@ -9,8 +10,8 @@ from homeassistant.const import UnitOfTemperature, UnitOfTime, REVOLUTIONS_PER_M from homeassistant.core import callback from homeassistant.helpers.entity import EntityCategory from pyhon.appliance import HonAppliance -from pyhon.parameter.fixed import HonParameterFixed +from . import const from .const import DOMAIN from .hon import HonEntity, unique_entities @@ -19,12 +20,13 @@ _LOGGER = logging.getLogger(__name__) @dataclass class HonSelectEntityDescription(SelectEntityDescription): - pass + option_list: Dict[str, str] = None @dataclass class HonConfigSelectEntityDescription(SelectEntityDescription): entity_category: EntityCategory = EntityCategory.CONFIG + option_list: Dict[str, str] = None SELECTS = { @@ -67,6 +69,7 @@ SELECTS = { name="Dry level", icon="mdi:hair-dryer", translation_key="dry_levels", + option_list=const.TUMBLE_DRYER_DRY_LEVEL, ), ), "OV": ( @@ -115,6 +118,7 @@ SELECTS = { name="Eco Pilot", icon="mdi:run", translation_key="eco_pilot", + option_list=const.AC_HUMAN_SENSE, ), ), "REF": ( @@ -158,13 +162,6 @@ class HonSelectEntity(HonEntity, SelectEntity): def __init__(self, hass, entry, device: HonAppliance, description) -> None: super().__init__(hass, entry, device, description) - if not (setting := self._device.settings.get(description.key)): - self._attr_options: list[str] = [] - elif not isinstance(setting, HonParameterFixed): - self._attr_options: list[str] = setting.values - else: - self._attr_options: list[str] = [setting.value] - @property def current_option(self) -> str | None: value = self._device.settings.get(self.entity_description.key) @@ -183,12 +180,20 @@ class HonSelectEntity(HonEntity, SelectEntity): setting = self._device.settings.get(self.entity_description.key) if setting is None: self._attr_available = False - self._attr_options: list[str] = [] - self._attr_native_value = None + self._attr_options: List[str] = [] + value = None else: self._attr_available = True - self._attr_options: list[str] = setting.values - self._attr_native_value = setting.value + self._attr_options: List[str] = setting.values + value = setting.value + if self.entity_description.option_list is not None: + self._attr_options = [ + self.entity_description.option_list.get(k, k) + for k in self._attr_options + ] + if value is not None: + value = self.entity_description.option_list.get(value, value) + self._attr_native_value = value if update: self.async_write_ha_state() diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index 3d2a124..0286811 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -1,6 +1,6 @@ import logging from dataclasses import dataclass -from typing import List +from typing import Dict from homeassistant.components.sensor import ( SensorEntity, @@ -21,7 +21,6 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers.entity import EntityCategory -from pyhon.appliance import HonAppliance from . import const from .const import DOMAIN @@ -33,11 +32,12 @@ _LOGGER = logging.getLogger(__name__) @dataclass class HonConfigSensorEntityDescription(SensorEntityDescription): entity_category: EntityCategory = EntityCategory.CONFIG + option_list: Dict[str, str] = None @dataclass class HonSensorEntityDescription(SensorEntityDescription): - option_list: List = None + option_list: Dict[str, str] = None SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { @@ -155,7 +155,9 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { key="dirtyLevel", name="Dirt level", icon="mdi:liquid-spot", + device_class=SensorDeviceClass.ENUM, translation_key="dirt_level", + option_list=const.DIRTY_LEVEL, ), HonConfigSensorEntityDescription( key="startProgram.suggestedLoadW", @@ -256,14 +258,18 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { HonConfigSensorEntityDescription( key="startProgram.steamLevel", name="Steam level", + device_class=SensorDeviceClass.ENUM, icon="mdi:smoke", translation_key="steam_level", + option_list=const.STEAM_LEVEL, ), HonSensorEntityDescription( key="steamLevel", name="Steam level", icon="mdi:smoke", + device_class=SensorDeviceClass.ENUM, translation_key="steam_level", + option_list=const.STEAM_LEVEL, ), HonConfigSensorEntityDescription( key="steamType", @@ -494,6 +500,14 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { device_class=SensorDeviceClass.ENUM, translation_key="programs_ac", ), + HonSensorEntityDescription( + key="machMode", + name="Machine Status", + icon="mdi:information", + device_class=SensorDeviceClass.ENUM, + translation_key="mach_modes_ac", + option_list=const.AC_MACH_MODE, + ), ), "REF": ( HonSensorEntityDescription( @@ -696,20 +710,16 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non class HonSensorEntity(HonEntity, SensorEntity): entity_description: HonSensorEntityDescription - def __init__(self, hass, entry, device: HonAppliance, description): - super().__init__(hass, entry, device, description) - if description.key == "programName": - self._attr_options = self._device.settings.get( - "startProgram.program" - ).values + ["No Program"] - elif description.option_list is not None: - self._attr_options = list(description.option_list.values()) - @callback def _handle_coordinator_update(self, update=True) -> None: value = self._device.get(self.entity_description.key, "") - if self.entity_description.option_list is not None: - value = self.entity_description.option_list[value] + if self.entity_description.key == "programName": + self._attr_options = self._device.settings.get( + "startProgram.program" + ).values + ["No Program"] + elif self.entity_description.option_list is not None: + self._attr_options = list(self.entity_description.option_list.values()) + value = self.entity_description.option_list.get(value, value) if not value and self.entity_description.state_class is not None: self._attr_native_value = 0 self._attr_native_value = value @@ -725,12 +735,16 @@ class HonConfigSensorEntity(HonEntity, SensorEntity): value = self._device.settings.get(self.entity_description.key, None) if self.entity_description.state_class is not None: if value and value.value: - self._attr_native_value = ( + value = ( float(value.value) if "." in str(value.value) else int(value.value) ) else: - self._attr_native_value = 0 + value = 0 else: - self._attr_native_value = value.value + value = value.value + if self.entity_description.option_list is not None and not value == 0: + self._attr_options = list(self.entity_description.option_list.values()) + value = self.entity_description.option_list.get(value, value) + self._attr_native_value = value if update: self.async_write_ha_state() diff --git a/custom_components/hon/translations/cs.json b/custom_components/hon/translations/cs.json index e034a44..2d66d47 100644 --- a/custom_components/hon/translations/cs.json +++ b/custom_components/hon/translations/cs.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Vypnuto", "avoid_touch": "Vyhybání", - "follow_touch": "Sledování" + "follow_touch": "Sledování", + "unknown": "unknown" }, "name": "Senzor osob" }, diff --git a/custom_components/hon/translations/de.json b/custom_components/hon/translations/de.json index 8c21355..7cf3cf3 100644 --- a/custom_components/hon/translations/de.json +++ b/custom_components/hon/translations/de.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Aus", "avoid_touch": "Berührung vermeiden", - "follow_touch": "Folgen" + "follow_touch": "Folgen", + "unknown": "unknown" }, "name": "Eco Pilot" }, diff --git a/custom_components/hon/translations/el.json b/custom_components/hon/translations/el.json index 24b419d..93d4665 100644 --- a/custom_components/hon/translations/el.json +++ b/custom_components/hon/translations/el.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Απενεργοποιηση", "avoid_touch": "Αποφύγετε την αφή", - "follow_touch": "Σας ακολουθεί" + "follow_touch": "Σας ακολουθεί", + "unknown": "unknown" }, "name": "Οικολογικός πιλότος" }, diff --git a/custom_components/hon/translations/en.json b/custom_components/hon/translations/en.json index 672e62d..f14fa71 100644 --- a/custom_components/hon/translations/en.json +++ b/custom_components/hon/translations/en.json @@ -894,7 +894,8 @@ "state": { "touch_off": "Off", "avoid_touch": "Avoid touch", - "follow_touch": "Follow" + "follow_touch": "Follow", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/es.json b/custom_components/hon/translations/es.json index 003d6e6..02dd717 100644 --- a/custom_components/hon/translations/es.json +++ b/custom_components/hon/translations/es.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Apagado", "avoid_touch": "Evitar el contacto", - "follow_touch": "Sígueme" + "follow_touch": "Sígueme", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/fr.json b/custom_components/hon/translations/fr.json index cb604dc..fe78f66 100644 --- a/custom_components/hon/translations/fr.json +++ b/custom_components/hon/translations/fr.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Désactivé", "avoid_touch": "Évitez de toucher", - "follow_touch": "Suivi" + "follow_touch": "Suivi", + "unknown": "unknown" }, "name": "Pilote éco" }, diff --git a/custom_components/hon/translations/he.json b/custom_components/hon/translations/he.json index feca9c3..7a0ff87 100644 --- a/custom_components/hon/translations/he.json +++ b/custom_components/hon/translations/he.json @@ -431,7 +431,8 @@ "state": { "touch_off": "Off", "avoid_touch": "Avoid touch", - "follow_touch": "Follow" + "follow_touch": "Follow", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/hr.json b/custom_components/hon/translations/hr.json index e96dc3f..385085f 100644 --- a/custom_components/hon/translations/hr.json +++ b/custom_components/hon/translations/hr.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Isključeno", "avoid_touch": "Izbjegavajte dodir", - "follow_touch": "Pratite" + "follow_touch": "Pratite", + "unknown": "unknown" }, "name": "Eko-pilot" }, diff --git a/custom_components/hon/translations/it.json b/custom_components/hon/translations/it.json index c076569..dcad47c 100644 --- a/custom_components/hon/translations/it.json +++ b/custom_components/hon/translations/it.json @@ -878,7 +878,8 @@ "state": { "touch_off": "Spento", "avoid_touch": "Avoid touch", - "follow_touch": "Segui" + "follow_touch": "Segui", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/nl.json b/custom_components/hon/translations/nl.json index f6737ed..ba5c686 100644 --- a/custom_components/hon/translations/nl.json +++ b/custom_components/hon/translations/nl.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Uit", "avoid_touch": "Voorkom aanraking", - "follow_touch": "Volgen" + "follow_touch": "Volgen", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/pl.json b/custom_components/hon/translations/pl.json index 6a36344..a9a0096 100644 --- a/custom_components/hon/translations/pl.json +++ b/custom_components/hon/translations/pl.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Wyłącz", "avoid_touch": "Unikanie kontaktu", - "follow_touch": "Podążanie" + "follow_touch": "Podążanie", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/pt.json b/custom_components/hon/translations/pt.json index 3d342c0..44ad0e8 100644 --- a/custom_components/hon/translations/pt.json +++ b/custom_components/hon/translations/pt.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Off", "avoid_touch": "Evitar o toque", - "follow_touch": "Seguir" + "follow_touch": "Seguir", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/ro.json b/custom_components/hon/translations/ro.json index b650ab2..d750b22 100644 --- a/custom_components/hon/translations/ro.json +++ b/custom_components/hon/translations/ro.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Oprit", "avoid_touch": "Evitați atingerea", - "follow_touch": "Urmărire" + "follow_touch": "Urmărire", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/ru.json b/custom_components/hon/translations/ru.json index b688ad0..ffecc52 100644 --- a/custom_components/hon/translations/ru.json +++ b/custom_components/hon/translations/ru.json @@ -873,7 +873,8 @@ "state": { "touch_off": "ВЫКЛ", "avoid_touch": "Не прикасайтесь", - "follow_touch": "Следование" + "follow_touch": "Следование", + "unknown": "unknown" }, "name": "Eco pilot" }, diff --git a/custom_components/hon/translations/sk.json b/custom_components/hon/translations/sk.json index dfc4ccf..1d84748 100644 --- a/custom_components/hon/translations/sk.json +++ b/custom_components/hon/translations/sk.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Off (Vypnúť)", "avoid_touch": "Nedotýkať sa", - "follow_touch": "Nasledovať" + "follow_touch": "Nasledovať", + "unknown": "unknown" }, "name": "Ekologický pilot" }, diff --git a/custom_components/hon/translations/sl.json b/custom_components/hon/translations/sl.json index 592a02c..cedf8f8 100644 --- a/custom_components/hon/translations/sl.json +++ b/custom_components/hon/translations/sl.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Izklop", "avoid_touch": "Brez dotika", - "follow_touch": "Sledenje" + "follow_touch": "Sledenje", + "unknown": "unknown" }, "name": "Eko pilot" }, diff --git a/custom_components/hon/translations/sr.json b/custom_components/hon/translations/sr.json index ca8fd65..aaa157e 100644 --- a/custom_components/hon/translations/sr.json +++ b/custom_components/hon/translations/sr.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Isključeno", "avoid_touch": "Izbegavajte dodir", - "follow_touch": "Pratiti" + "follow_touch": "Pratiti", + "unknown": "unknown" }, "name": "Eko pilot" }, diff --git a/custom_components/hon/translations/tr.json b/custom_components/hon/translations/tr.json index 0af9515..562fd7f 100644 --- a/custom_components/hon/translations/tr.json +++ b/custom_components/hon/translations/tr.json @@ -873,7 +873,8 @@ "state": { "touch_off": "Kapali", "avoid_touch": "Dokunmaktan kaçının", - "follow_touch": "Takip et" + "follow_touch": "Takip et", + "unknown": "unknown" }, "name": "Eko pilot" }, diff --git a/custom_components/hon/translations/zh.json b/custom_components/hon/translations/zh.json index efb9296..0c2111e 100644 --- a/custom_components/hon/translations/zh.json +++ b/custom_components/hon/translations/zh.json @@ -873,7 +873,8 @@ "state": { "touch_off": "关闭", "avoid_touch": "避免触摸", - "follow_touch": "跟随" + "follow_touch": "跟随", + "unknown": "unknown" }, "name": "节能模式" }, diff --git a/scripts/translation_keys.py b/scripts/translation_keys.py index 9f475cc..57b5364 100644 --- a/scripts/translation_keys.py +++ b/scripts/translation_keys.py @@ -35,6 +35,7 @@ DIRTY_LEVEL = { "little": "WASHING_CMD&CTRL.PROGRAM_CYCLE_DETAIL_OPTIONS_VALUES_DESCRIPTION.LITTLE", "normal": "WASHING_CMD&CTRL.PROGRAM_CYCLE_DETAIL_OPTIONS_VALUES_DESCRIPTION.NORMAL", "very": "WASHING_CMD&CTRL.PROGRAM_CYCLE_DETAIL_OPTIONS_VALUES_DESCRIPTION.VERY", + "unknown": "unknown", } STEAM_LEVEL = { @@ -81,6 +82,7 @@ AC_HUMAN_SENSE = { "touch_off": "AC.PROGRAM_DETAIL.TOUCH_OFF", "avoid_touch": "AC.PROGRAM_DETAIL.AVOID_TOUCH", "follow_touch": "AC.PROGRAM_DETAIL.FOLLOW_TOUCH", + "unknown": "unknown", } REF_ZONES = {