Readable internal names for some selects

This commit is contained in:
Andre Basche 2023-06-12 00:20:38 +02:00
parent 52c3a861de
commit dfa5735bc2
25 changed files with 93 additions and 50 deletions

View File

@ -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` |

View File

@ -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",
}

View File

@ -11,5 +11,5 @@
"requirements": [
"pyhOn==0.13.0"
],
"version": "0.9.0-beta.1"
"version": "0.9.0-beta.2"
}

View File

@ -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()

View File

@ -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()

View File

@ -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"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Aus",
"avoid_touch": "Berührung vermeiden",
"follow_touch": "Folgen"
"follow_touch": "Folgen",
"unknown": "unknown"
},
"name": "Eco Pilot"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Απενεργοποιηση",
"avoid_touch": "Αποφύγετε την αφή",
"follow_touch": "Σας ακολουθεί"
"follow_touch": "Σας ακολουθεί",
"unknown": "unknown"
},
"name": "Οικολογικός πιλότος"
},

View File

@ -894,7 +894,8 @@
"state": {
"touch_off": "Off",
"avoid_touch": "Avoid touch",
"follow_touch": "Follow"
"follow_touch": "Follow",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -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"
},

View File

@ -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"
},

View File

@ -431,7 +431,8 @@
"state": {
"touch_off": "Off",
"avoid_touch": "Avoid touch",
"follow_touch": "Follow"
"follow_touch": "Follow",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Isključeno",
"avoid_touch": "Izbjegavajte dodir",
"follow_touch": "Pratite"
"follow_touch": "Pratite",
"unknown": "unknown"
},
"name": "Eko-pilot"
},

View File

@ -878,7 +878,8 @@
"state": {
"touch_off": "Spento",
"avoid_touch": "Avoid touch",
"follow_touch": "Segui"
"follow_touch": "Segui",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Uit",
"avoid_touch": "Voorkom aanraking",
"follow_touch": "Volgen"
"follow_touch": "Volgen",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -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"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Off",
"avoid_touch": "Evitar o toque",
"follow_touch": "Seguir"
"follow_touch": "Seguir",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -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"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "ВЫКЛ",
"avoid_touch": "Не прикасайтесь",
"follow_touch": "Следование"
"follow_touch": "Следование",
"unknown": "unknown"
},
"name": "Eco pilot"
},

View File

@ -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"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Izklop",
"avoid_touch": "Brez dotika",
"follow_touch": "Sledenje"
"follow_touch": "Sledenje",
"unknown": "unknown"
},
"name": "Eko pilot"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "Isključeno",
"avoid_touch": "Izbegavajte dodir",
"follow_touch": "Pratiti"
"follow_touch": "Pratiti",
"unknown": "unknown"
},
"name": "Eko pilot"
},

View File

@ -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"
},

View File

@ -873,7 +873,8 @@
"state": {
"touch_off": "关闭",
"avoid_touch": "避免触摸",
"follow_touch": "跟随"
"follow_touch": "跟随",
"unknown": "unknown"
},
"name": "节能模式"
},

View File

@ -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 = {