2023-02-18 20:58:21 -05:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-05-27 18:30:08 -04:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
2023-02-18 20:58:21 -05:00
|
|
|
from homeassistant.components.number import (
|
|
|
|
NumberEntity,
|
|
|
|
NumberEntityDescription,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2023-04-07 07:52:55 -04:00
|
|
|
from homeassistant.const import UnitOfTime, UnitOfTemperature
|
2023-02-18 20:58:21 -05:00
|
|
|
from homeassistant.core import callback
|
2023-06-08 14:01:55 -04:00
|
|
|
from homeassistant.helpers.entity import EntityCategory
|
2023-07-23 15:52:42 -04:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
|
|
|
from pyhon.appliance import HonAppliance
|
2023-05-10 12:13:05 -04:00
|
|
|
from pyhon.parameter.range import HonParameterRange
|
2023-03-03 12:23:30 -05:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
2023-05-24 19:30:33 -04:00
|
|
|
from .hon import HonEntity, unique_entities
|
2023-02-18 20:58:21 -05:00
|
|
|
|
2023-05-27 18:30:08 -04:00
|
|
|
|
2024-01-10 18:41:49 -05:00
|
|
|
@dataclass(frozen=True)
|
2023-05-27 18:30:08 -04:00
|
|
|
class HonConfigNumberEntityDescription(NumberEntityDescription):
|
|
|
|
entity_category: EntityCategory = EntityCategory.CONFIG
|
|
|
|
|
|
|
|
|
2024-01-10 18:41:49 -05:00
|
|
|
@dataclass(frozen=True)
|
2023-05-27 18:30:08 -04:00
|
|
|
class HonNumberEntityDescription(NumberEntityDescription):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2023-02-18 20:58:21 -05:00
|
|
|
NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
|
|
|
|
"WM": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-03-03 12:23:30 -05:00
|
|
|
key="startProgram.delayTime",
|
|
|
|
name="Delay Time",
|
2023-03-08 17:00:55 -05:00
|
|
|
icon="mdi:timer-plus",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="delay_time",
|
2023-02-18 20:58:21 -05:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-03-03 12:23:30 -05:00
|
|
|
key="startProgram.rinseIterations",
|
|
|
|
name="Rinse Iterations",
|
2023-03-08 17:00:55 -05:00
|
|
|
icon="mdi:rotate-right",
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="rinse_iterations",
|
2023-02-18 20:58:21 -05:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-03-03 12:23:30 -05:00
|
|
|
key="startProgram.mainWashTime",
|
|
|
|
name="Main Wash Time",
|
2023-03-08 17:00:55 -05:00
|
|
|
icon="mdi:clock-start",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="wash_time",
|
2023-02-18 20:58:21 -05:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-05-06 20:10:30 -04:00
|
|
|
key="startProgram.waterHard",
|
|
|
|
name="Water hard",
|
|
|
|
icon="mdi:water",
|
|
|
|
translation_key="water_hard",
|
|
|
|
),
|
2023-09-29 11:24:21 -04:00
|
|
|
HonNumberEntityDescription(
|
|
|
|
key="settings.waterHard",
|
|
|
|
name="Water hard",
|
|
|
|
icon="mdi:water",
|
|
|
|
translation_key="water_hard",
|
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-05-06 20:10:30 -04:00
|
|
|
key="startProgram.lang",
|
|
|
|
name="lang",
|
|
|
|
),
|
2023-02-18 20:58:21 -05:00
|
|
|
),
|
2023-03-21 08:03:39 -04:00
|
|
|
"TD": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-03-21 08:03:39 -04:00
|
|
|
key="startProgram.delayTime",
|
|
|
|
name="Delay time",
|
|
|
|
icon="mdi:timer-plus",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="delay_time",
|
2023-03-21 08:03:39 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-03-21 08:03:39 -04:00
|
|
|
key="startProgram.tempLevel",
|
|
|
|
name="Temperature level",
|
|
|
|
icon="mdi:thermometer",
|
2023-04-10 13:51:16 -04:00
|
|
|
translation_key="tumbledryertemplevel",
|
2023-03-21 08:03:39 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-23 10:24:30 -04:00
|
|
|
key="startProgram.dryTime",
|
|
|
|
name="Dry Time",
|
|
|
|
translation_key="dry_time",
|
|
|
|
),
|
2023-03-21 08:03:39 -04:00
|
|
|
),
|
2023-04-07 07:52:55 -04:00
|
|
|
"OV": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-07 07:52:55 -04:00
|
|
|
key="startProgram.delayTime",
|
|
|
|
name="Delay time",
|
|
|
|
icon="mdi:timer-plus",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="delay_time",
|
2023-04-07 07:52:55 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-07 07:52:55 -04:00
|
|
|
key="startProgram.tempSel",
|
|
|
|
name="Target Temperature",
|
|
|
|
icon="mdi:thermometer",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="target_temperature",
|
2023-04-07 07:52:55 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-07 07:52:55 -04:00
|
|
|
key="startProgram.prTime",
|
|
|
|
name="Program Duration",
|
|
|
|
icon="mdi:timelapse",
|
2023-04-10 13:51:16 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="program_duration",
|
2023-04-07 07:52:55 -04:00
|
|
|
),
|
2023-04-07 22:44:47 -04:00
|
|
|
),
|
2023-04-16 07:55:08 -04:00
|
|
|
"IH": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-14 22:27:40 -04:00
|
|
|
key="startProgram.temp",
|
|
|
|
name="Temperature",
|
|
|
|
icon="mdi:thermometer",
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="temperature",
|
2023-04-14 22:27:40 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-14 22:27:40 -04:00
|
|
|
key="startProgram.powerManagement",
|
|
|
|
name="Power Management",
|
|
|
|
icon="mdi:timelapse",
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="power_management",
|
2023-04-14 22:27:40 -04:00
|
|
|
),
|
|
|
|
),
|
2023-04-16 15:46:17 -04:00
|
|
|
"DW": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-16 15:46:17 -04:00
|
|
|
key="startProgram.delayTime",
|
|
|
|
name="Delay time",
|
|
|
|
icon="mdi:timer-plus",
|
|
|
|
native_unit_of_measurement=UnitOfTime.MINUTES,
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="delay_time",
|
2023-04-16 15:46:17 -04:00
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonConfigNumberEntityDescription(
|
2023-04-16 15:46:17 -04:00
|
|
|
key="startProgram.waterHard",
|
|
|
|
name="Water hard",
|
|
|
|
icon="mdi:water",
|
2023-04-22 20:01:14 -04:00
|
|
|
translation_key="water_hard",
|
2023-04-16 15:46:17 -04:00
|
|
|
),
|
|
|
|
),
|
2023-04-26 17:57:44 -04:00
|
|
|
"AC": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonNumberEntityDescription(
|
2023-05-07 20:05:04 -04:00
|
|
|
key="settings.tempSel",
|
2023-04-26 17:57:44 -04:00
|
|
|
name="Target Temperature",
|
|
|
|
icon="mdi:thermometer",
|
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
|
|
translation_key="target_temperature",
|
|
|
|
),
|
|
|
|
),
|
2023-05-14 18:38:41 -04:00
|
|
|
"REF": (
|
2023-05-27 18:30:08 -04:00
|
|
|
HonNumberEntityDescription(
|
2023-05-14 18:38:41 -04:00
|
|
|
key="settings.tempSelZ1",
|
|
|
|
name="Fridge Temperature",
|
|
|
|
icon="mdi:thermometer",
|
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
|
|
translation_key="fridge_temp_sel",
|
|
|
|
),
|
2023-05-27 18:30:08 -04:00
|
|
|
HonNumberEntityDescription(
|
2023-05-14 18:38:41 -04:00
|
|
|
key="settings.tempSelZ2",
|
|
|
|
name="Freezer Temperature",
|
|
|
|
icon="mdi:thermometer",
|
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
|
|
translation_key="freezer_temp_sel",
|
|
|
|
),
|
2023-11-20 11:35:58 -05:00
|
|
|
HonNumberEntityDescription(
|
|
|
|
key="settings.tempSelZ3",
|
|
|
|
name="MyZone Temperature",
|
|
|
|
icon="mdi:thermometer",
|
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
|
|
translation_key="my_zone_temp_sel",
|
|
|
|
),
|
2023-05-14 18:38:41 -04:00
|
|
|
),
|
2023-06-20 18:59:00 -04:00
|
|
|
"AP": (
|
|
|
|
HonNumberEntityDescription(
|
|
|
|
key="settings.aromaTimeOn",
|
|
|
|
name="Aroma Time On",
|
2023-07-09 18:19:43 -04:00
|
|
|
icon="mdi:scent",
|
2023-06-20 18:59:00 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.SECONDS,
|
2023-07-09 18:19:43 -04:00
|
|
|
translation_key="aroma_time_on",
|
2023-06-20 18:59:00 -04:00
|
|
|
),
|
|
|
|
HonNumberEntityDescription(
|
|
|
|
key="settings.aromaTimeOff",
|
|
|
|
name="Aroma Time Off",
|
2023-07-09 18:19:43 -04:00
|
|
|
icon="mdi:scent-off",
|
2023-06-20 18:59:00 -04:00
|
|
|
native_unit_of_measurement=UnitOfTime.SECONDS,
|
2023-07-09 18:19:43 -04:00
|
|
|
translation_key="aroma_time_off",
|
2023-06-20 18:59:00 -04:00
|
|
|
),
|
|
|
|
HonNumberEntityDescription(
|
|
|
|
key="settings.pollenLevel",
|
|
|
|
name="Pollen Level",
|
2023-07-09 18:19:43 -04:00
|
|
|
icon="mdi:flower-pollen",
|
2023-06-30 19:45:32 -04:00
|
|
|
translation_key="pollen_level",
|
2023-05-29 23:22:02 -04:00
|
|
|
),
|
|
|
|
),
|
2023-02-18 20:58:21 -05:00
|
|
|
}
|
|
|
|
|
2023-05-07 10:39:45 -04:00
|
|
|
NUMBERS["WD"] = unique_entities(NUMBERS["WM"], NUMBERS["TD"])
|
|
|
|
|
2023-02-18 20:58:21 -05:00
|
|
|
|
2023-07-23 15:52:42 -04:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2023-05-24 19:30:33 -04:00
|
|
|
entities = []
|
2023-07-23 15:52:42 -04:00
|
|
|
entity: HonNumberEntity | HonConfigNumberEntity
|
2023-05-24 19:30:33 -04:00
|
|
|
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
|
|
|
for description in NUMBERS.get(device.appliance_type, []):
|
|
|
|
if description.key not in device.available_settings:
|
|
|
|
continue
|
2023-05-27 18:30:08 -04:00
|
|
|
if isinstance(description, HonNumberEntityDescription):
|
|
|
|
entity = HonNumberEntity(hass, entry, device, description)
|
|
|
|
elif isinstance(description, HonConfigNumberEntityDescription):
|
|
|
|
entity = HonConfigNumberEntity(hass, entry, device, description)
|
|
|
|
else:
|
|
|
|
continue
|
2023-05-24 19:30:33 -04:00
|
|
|
await entity.coordinator.async_config_entry_first_refresh()
|
|
|
|
entities.append(entity)
|
|
|
|
async_add_entities(entities)
|
2023-02-18 20:58:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
class HonNumberEntity(HonEntity, NumberEntity):
|
2023-05-27 18:30:08 -04:00
|
|
|
entity_description: HonNumberEntityDescription
|
|
|
|
|
2023-07-23 15:52:42 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
hass: HomeAssistantType,
|
|
|
|
entry: ConfigEntry,
|
|
|
|
device: HonAppliance,
|
|
|
|
description: HonNumberEntityDescription,
|
|
|
|
) -> None:
|
2023-05-27 18:30:08 -04:00
|
|
|
super().__init__(hass, entry, device, description)
|
2023-02-18 20:58:21 -05:00
|
|
|
|
|
|
|
self._data = device.settings[description.key]
|
|
|
|
if isinstance(self._data, HonParameterRange):
|
|
|
|
self._attr_native_max_value = self._data.max
|
|
|
|
self._attr_native_min_value = self._data.min
|
|
|
|
self._attr_native_step = self._data.step
|
|
|
|
|
|
|
|
@property
|
|
|
|
def native_value(self) -> float | None:
|
2023-07-23 15:52:42 -04:00
|
|
|
if value := self._device.get(self.entity_description.key.split(".")[-1]):
|
|
|
|
return float(value)
|
|
|
|
return None
|
2023-02-18 20:58:21 -05:00
|
|
|
|
|
|
|
async def async_set_native_value(self, value: float) -> None:
|
2023-04-23 22:36:14 -04:00
|
|
|
setting = self._device.settings[self.entity_description.key]
|
2023-05-27 18:30:08 -04:00
|
|
|
if isinstance(setting, HonParameterRange):
|
2023-04-23 22:36:14 -04:00
|
|
|
setting.value = value
|
2023-05-27 18:30:08 -04:00
|
|
|
command = self.entity_description.key.split(".")[0]
|
|
|
|
await self._device.commands[command].send()
|
2023-06-21 13:52:32 -04:00
|
|
|
if command != "settings":
|
|
|
|
self._device.sync_command(command, "settings")
|
2023-04-23 14:04:19 -04:00
|
|
|
await self.coordinator.async_refresh()
|
2023-02-18 20:58:21 -05:00
|
|
|
|
|
|
|
@callback
|
2023-07-23 15:52:42 -04:00
|
|
|
def _handle_coordinator_update(self, update: bool = True) -> None:
|
2023-03-08 17:00:55 -05:00
|
|
|
setting = self._device.settings[self.entity_description.key]
|
|
|
|
if isinstance(setting, HonParameterRange):
|
|
|
|
self._attr_native_max_value = setting.max
|
|
|
|
self._attr_native_min_value = setting.min
|
|
|
|
self._attr_native_step = setting.step
|
2023-06-20 18:59:00 -04:00
|
|
|
self._attr_native_value = self.native_value
|
2023-06-08 14:01:55 -04:00
|
|
|
if update:
|
|
|
|
self.async_write_ha_state()
|
2023-05-15 13:23:53 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return True if entity is available."""
|
2023-05-27 18:30:08 -04:00
|
|
|
return (
|
|
|
|
super().available
|
2023-06-12 18:14:51 -04:00
|
|
|
and int(self._device.get("remoteCtrValid", 1)) == 1
|
2023-05-27 18:30:08 -04:00
|
|
|
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-07-23 15:52:42 -04:00
|
|
|
class HonConfigNumberEntity(HonEntity, NumberEntity):
|
2023-05-27 18:30:08 -04:00
|
|
|
entity_description: HonConfigNumberEntityDescription
|
|
|
|
|
2023-07-23 15:52:42 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
hass: HomeAssistantType,
|
|
|
|
entry: ConfigEntry,
|
|
|
|
device: HonAppliance,
|
|
|
|
description: HonConfigNumberEntityDescription,
|
|
|
|
) -> None:
|
|
|
|
super().__init__(hass, entry, device, description)
|
|
|
|
|
|
|
|
self._data = device.settings[description.key]
|
|
|
|
if isinstance(self._data, HonParameterRange):
|
|
|
|
self._attr_native_max_value = self._data.max
|
|
|
|
self._attr_native_min_value = self._data.min
|
|
|
|
self._attr_native_step = self._data.step
|
|
|
|
|
2023-06-30 14:09:55 -04:00
|
|
|
@property
|
|
|
|
def native_value(self) -> float | None:
|
2023-07-23 15:52:42 -04:00
|
|
|
if value := self._device.settings[self.entity_description.key].value:
|
|
|
|
return float(value)
|
|
|
|
return None
|
2023-06-30 14:09:55 -04:00
|
|
|
|
2023-07-23 15:52:42 -04:00
|
|
|
async def async_set_native_value(self, value: float) -> None:
|
2023-05-27 18:30:08 -04:00
|
|
|
setting = self._device.settings[self.entity_description.key]
|
|
|
|
if isinstance(setting, HonParameterRange):
|
|
|
|
setting.value = value
|
|
|
|
await self.coordinator.async_refresh()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return super(NumberEntity, self).available
|
2023-07-23 15:52:42 -04:00
|
|
|
|
|
|
|
@callback
|
|
|
|
def _handle_coordinator_update(self, update: bool = True) -> None:
|
|
|
|
setting = self._device.settings[self.entity_description.key]
|
|
|
|
if isinstance(setting, HonParameterRange):
|
|
|
|
self._attr_native_max_value = setting.max
|
|
|
|
self._attr_native_min_value = setting.min
|
|
|
|
self._attr_native_step = setting.step
|
|
|
|
self._attr_native_value = self.native_value
|
|
|
|
if update:
|
|
|
|
self.async_write_ha_state()
|