1
0
mirror of https://github.com/Andre0512/hon.git synced 2024-12-21 20:05:56 +01:00
hOn/custom_components/hon/sensor.py

864 lines
31 KiB
Python
Raw Normal View History

2023-02-19 02:58:21 +01:00
import logging
2023-05-28 00:30:08 +02:00
from dataclasses import dataclass
2023-02-19 02:58:21 +01:00
from homeassistant.components.sensor import (
SensorEntity,
SensorDeviceClass,
SensorStateClass,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
2023-06-21 00:59:00 +02:00
from homeassistant.const import (
PERCENTAGE,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
)
2023-04-08 04:44:47 +02:00
from homeassistant.const import (
REVOLUTIONS_PER_MINUTE,
UnitOfEnergy,
UnitOfVolume,
UnitOfMass,
UnitOfPower,
UnitOfTime,
2023-04-10 19:51:16 +02:00
UnitOfTemperature,
2023-04-08 04:44:47 +02:00
)
2023-02-19 02:58:21 +01:00
from homeassistant.core import callback
2023-03-03 18:23:30 +01:00
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
2023-06-08 20:01:55 +02:00
from . import const
2023-02-19 02:58:21 +01:00
from .const import DOMAIN
2023-06-13 00:14:51 +02:00
from .hon import HonEntity, unique_entities, get_readable
2023-02-19 02:58:21 +01:00
_LOGGER = logging.getLogger(__name__)
2024-01-11 00:41:49 +01:00
@dataclass(frozen=True)
2023-05-28 00:30:08 +02:00
class HonConfigSensorEntityDescription(SensorEntityDescription):
2023-11-21 01:26:38 +01:00
entity_category: EntityCategory = EntityCategory.DIAGNOSTIC
option_list: dict[int, str] | None = None
2023-05-28 00:30:08 +02:00
2024-01-11 00:41:49 +01:00
@dataclass(frozen=True)
2023-05-28 00:30:08 +02:00
class HonSensorEntityDescription(SensorEntityDescription):
option_list: dict[int, str] | None = None
2023-05-28 00:30:08 +02:00
2023-02-19 02:58:21 +01:00
SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
"WM": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-22 02:47:55 +02:00
key="prPhase",
name="Program Phase",
icon="mdi:washing-machine",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="program_phases_wm",
2023-06-11 22:34:32 +02:00
option_list=const.WASHING_PR_PHASE,
2023-04-22 02:47:55 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-02-19 02:58:21 +01:00
key="totalElectricityUsed",
name="Total Power",
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
2023-04-10 19:51:16 +02:00
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
2023-04-24 21:38:05 +02:00
translation_key="energy_total",
2023-02-19 02:58:21 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-02-19 02:58:21 +01:00
key="totalWaterUsed",
name="Total Water",
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
2023-04-10 19:51:16 +02:00
native_unit_of_measurement=UnitOfVolume.LITERS,
2023-04-24 21:38:05 +02:00
translation_key="water_total",
2023-02-19 02:58:21 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-02-19 02:58:21 +01:00
key="totalWashCycle",
name="Total Wash Cycle",
state_class=SensorStateClass.TOTAL_INCREASING,
2023-04-10 19:51:16 +02:00
icon="mdi:counter",
2023-04-24 21:38:05 +02:00
translation_key="cycles_total",
2023-02-19 02:58:21 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-02-19 02:58:21 +01:00
key="currentElectricityUsed",
name="Current Electricity Used",
state_class=SensorStateClass.MEASUREMENT,
2023-03-05 00:54:57 +01:00
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
2023-04-10 19:51:16 +02:00
icon="mdi:lightning-bolt",
2023-04-24 21:38:05 +02:00
translation_key="energy_current",
2023-02-19 02:58:21 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-02-19 02:58:21 +01:00
key="currentWaterUsed",
name="Current Water Used",
state_class=SensorStateClass.MEASUREMENT,
2023-04-10 19:51:16 +02:00
icon="mdi:water",
2023-04-24 21:38:05 +02:00
translation_key="water_current",
2023-02-19 02:58:21 +01:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-03-03 18:23:30 +01:00
key="startProgram.weight",
2023-03-05 19:19:52 +01:00
name="Suggested weight",
2023-03-03 18:23:30 +01:00
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
2023-04-10 19:51:16 +02:00
icon="mdi:weight-kilogram",
translation_key="suggested_load",
2023-03-03 18:23:30 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-05 00:54:57 +01:00
key="machMode",
2023-03-08 23:00:55 +01:00
name="Machine Status",
2023-03-05 19:19:52 +01:00
icon="mdi:information",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="washing_modes",
2023-06-11 22:34:32 +02:00
option_list=const.MACH_MODE,
2023-03-05 00:54:57 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-10 19:51:16 +02:00
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
2023-03-05 00:54:57 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-05 21:16:09 +01:00
key="remainingTimeMM",
name="Remaining Time",
icon="mdi:timer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="remaining_time",
2023-03-05 21:16:09 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-05 21:16:09 +01:00
key="spinSpeed",
name="Spin Speed",
2023-03-22 22:57:14 +01:00
icon="mdi:speedometer",
2023-03-05 21:16:09 +01:00
state_class=SensorStateClass.MEASUREMENT,
2023-05-07 16:39:45 +02:00
native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
2023-04-23 02:01:14 +02:00
translation_key="spin_speed",
2023-03-05 21:16:09 +01:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.energyLabel",
name="Energy Label",
icon="mdi:lightning-bolt-circle",
state_class=SensorStateClass.MEASUREMENT,
translation_key="energy_label",
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.liquidDetergentDose",
name="Liquid Detergent Dose",
icon="mdi:cup-water",
translation_key="det_liquid",
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.powderDetergentDose",
name="Powder Detergent Dose",
icon="mdi:cup",
translation_key="det_dust",
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-05-07 00:52:54 +02:00
key="startProgram.remainingTime",
name="Remaining Time",
icon="mdi:timer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
translation_key="remaining_time",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
key="dirtyLevel",
2023-07-10 00:48:57 +02:00
name="Dirty level",
icon="mdi:liquid-spot",
device_class=SensorDeviceClass.ENUM,
translation_key="dirt_level",
option_list=const.DIRTY_LEVEL,
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.suggestedLoadW",
name="Suggested Load",
icon="mdi:weight-kilogram",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
2023-12-14 16:38:53 +01:00
translation_key="suggested_load_wash",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-08 19:39:52 +02:00
key="temp",
name="Current Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="temperature",
),
2023-05-29 19:07:52 +02:00
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_wm",
),
2023-07-10 00:20:35 +02:00
HonSensorEntityDescription(
key="steamLevel",
name="Steam level",
icon="mdi:weather-dust",
device_class=SensorDeviceClass.ENUM,
translation_key="steam_level",
option_list=const.STEAM_LEVEL,
),
2023-10-02 03:33:45 +02:00
HonSensorEntityDescription(
key="stainType",
name="Stain Type",
icon="mdi:liquid-spot",
device_class=SensorDeviceClass.ENUM,
translation_key="stain_type",
option_list=const.STAIN_TYPES,
),
2023-03-21 12:59:39 +01:00
),
"TD": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="machMode",
name="Machine Status",
icon="mdi:information",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="washing_modes",
2023-06-11 22:34:32 +02:00
option_list=const.MACH_MODE,
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-10 19:51:16 +02:00
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="remainingTimeMM",
name="Remaining Time",
icon="mdi:timer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="remaining_time",
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="delayTime",
name="Start Time",
icon="mdi:clock-start",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="delay_time",
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
key="programName",
2023-03-21 12:59:39 +01:00
name="Program",
2023-05-29 19:07:52 +02:00
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_td",
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="prPhase",
name="Program Phase",
2023-04-22 02:47:55 +02:00
icon="mdi:washing-machine",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="program_phases_td",
2023-06-11 22:34:32 +02:00
option_list=const.TUMBLE_DRYER_PR_PHASE,
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="dryLevel",
name="Dry level",
icon="mdi:hair-dryer",
device_class=SensorDeviceClass.ENUM,
2023-04-22 23:09:57 +02:00
translation_key="dry_levels",
2023-06-11 22:34:32 +02:00
option_list=const.TUMBLE_DRYER_DRY_LEVEL,
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-03-21 12:59:39 +01:00
key="tempLevel",
name="Temperature level",
icon="mdi:thermometer",
2023-04-10 19:51:16 +02:00
translation_key="tumbledryertemplevel",
2023-03-21 12:59:39 +01:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.suggestedLoadD",
name="Suggested Load",
icon="mdi:weight-kilogram",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
2023-12-14 16:38:53 +01:00
translation_key="suggested_load_dry",
),
HonConfigSensorEntityDescription(
key="startProgram.suggestedLoadWD",
name="Suggested Load Wash & Dry",
icon="mdi:weight-kilogram",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
translation_key="suggested_load_wash_dry",
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
key="startProgram.energyLabel",
name="Energy Label",
icon="mdi:lightning-bolt-circle",
state_class=SensorStateClass.MEASUREMENT,
translation_key="energy_label",
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-05-07 16:39:45 +02:00
key="steamType",
name="Steam Type",
icon="mdi:weather-dust",
2023-04-08 04:44:47 +02:00
),
),
2023-04-07 13:52:55 +02:00
"OV": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-07 13:52:55 +02:00
key="remainingTimeMM",
name="Remaining Time",
icon="mdi:timer",
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="remaining_time",
2023-04-07 13:52:55 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-07 13:52:55 +02:00
key="delayTime",
name="Start Time",
icon="mdi:clock-start",
2023-04-23 02:01:14 +02:00
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
translation_key="delay_time",
2023-04-07 13:52:55 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-07 13:52:55 +02:00
key="temp",
name="Temperature",
icon="mdi:thermometer",
2023-04-23 02:01:14 +02:00
translation_key="temperature",
2023-04-07 13:52:55 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-07 13:52:55 +02:00
key="tempSel",
name="Temperature Selected",
icon="mdi:thermometer",
2023-04-23 02:01:14 +02:00
translation_key="target_temperature",
2023-04-07 13:52:55 +02:00
),
2023-05-29 19:07:52 +02:00
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_ov",
),
2023-04-08 04:44:47 +02:00
),
2023-04-16 13:55:08 +02:00
"IH": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-15 04:27:40 +02:00
key="remainingTimeMM",
name="Remaining Time",
icon="mdi:timer",
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="remaining_time",
2023-04-15 04:27:40 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-15 04:27:40 +02:00
key="temp",
name="Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
2023-04-23 02:01:14 +02:00
translation_key="temperature",
2023-04-15 04:27:40 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-24 21:38:05 +02:00
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-18 23:44:23 +02:00
key="power",
name="Power",
icon="mdi:lightning-bolt",
state_class=SensorStateClass.MEASUREMENT,
2023-04-23 02:01:14 +02:00
translation_key="power",
2023-04-18 23:44:23 +02:00
),
2023-05-29 19:07:52 +02:00
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_ih",
),
2023-04-15 04:27:40 +02:00
),
2023-04-16 21:46:17 +02:00
"DW": (
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.ecoIndex",
name="Eco Index",
icon="mdi:sprout",
state_class=SensorStateClass.MEASUREMENT,
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.waterEfficiency",
name="Water Efficiency",
icon="mdi:water",
state_class=SensorStateClass.MEASUREMENT,
2023-04-23 02:01:14 +02:00
translation_key="water_efficiency",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.waterSaving",
name="Water Saving",
icon="mdi:water-percent",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
2023-04-23 02:01:14 +02:00
translation_key="water_saving",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.temp",
name="Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
2023-04-23 02:01:14 +02:00
translation_key="temperature",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.energyLabel",
name="Energy Label",
icon="mdi:lightning-bolt-circle",
state_class=SensorStateClass.MEASUREMENT,
translation_key="energy_label",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonConfigSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="startProgram.remainingTime",
name="Time",
icon="mdi:timer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="duration",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="machMode",
name="Machine Status",
icon="mdi:information",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="washing_modes",
2023-06-11 22:34:32 +02:00
option_list=const.MACH_MODE,
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-16 21:46:17 +02:00
key="remainingTimeMM",
name="Remaining Time",
icon="mdi:timer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
2023-04-23 02:01:14 +02:00
translation_key="remaining_time",
2023-04-16 21:46:17 +02:00
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-04-22 02:47:55 +02:00
key="prPhase",
name="Program Phase",
icon="mdi:washing-machine",
device_class=SensorDeviceClass.ENUM,
2023-04-22 02:47:55 +02:00
translation_key="program_phases_dw",
2023-06-11 22:34:32 +02:00
option_list=const.DISHWASHER_PR_PHASE,
2023-04-22 02:47:55 +02:00
),
2023-05-29 19:07:52 +02:00
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_dw",
),
2023-04-16 21:46:17 +02:00
),
2023-05-17 00:01:33 +02:00
"AC": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempAirOutdoor",
name="Air Temperature Outdoor",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempCoilerIndoor",
name="Coiler Temperature Indoor",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempCoilerOutdoor",
name="Coiler Temperature Outside",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempDefrostOutdoor",
name="Defrost Temperature Outdoor",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempInAirOutdoor",
name="In Air Temperature Outdoor",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempIndoor",
name="Indoor Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempOutdoor",
name="Outdoor Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-17 00:01:33 +02:00
key="tempSel",
name="Selected Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
2023-06-10 06:44:19 +02:00
translation_key="target_temperature",
2023-05-17 00:01:33 +02:00
),
2023-05-29 19:07:52 +02:00
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
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,
),
2023-05-17 00:01:33 +02:00
),
2023-05-10 18:13:05 +02:00
"REF": (
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-10 18:13:05 +02:00
key="humidityEnv",
name="Room Humidity",
icon="mdi:water-percent",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-10 18:13:05 +02:00
key="tempEnv",
name="Room Temperature",
icon="mdi:home-thermometer-outline",
2023-05-10 18:13:05 +02:00
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="room_temperature",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
key="tempZ1",
name="Temperature Fridge",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="fridge_temp",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
key="tempZ2",
name="Temperature Freezer",
icon="mdi:snowflake-thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="freezer_temp",
),
2023-05-28 00:30:08 +02:00
HonSensorEntityDescription(
2023-05-21 20:51:20 +02:00
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
),
HonSensorEntityDescription(
key="humidityLevel",
name="Humidity Level",
icon="mdi:water-outline",
device_class=SensorDeviceClass.ENUM,
translation_key="humidity_level",
option_list=const.REF_HUMIDITY_LEVELS,
),
2023-05-10 18:13:05 +02:00
),
"HO": (
HonSensorEntityDescription(
key="delayTime",
name="Delay time",
icon="mdi:clock-start",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
HonSensorEntityDescription(
key="delayTimeStatus",
name="Delay time status",
icon="mdi:clock-start",
),
HonSensorEntityDescription(
key="errors",
name="Errors",
icon="mdi:alert-circle",
),
HonSensorEntityDescription(
key="filterCleaningAlarmStatus",
name="Filter Cleaning Alarm Status",
),
HonSensorEntityDescription(
key="filterCleaningStatus",
name="Filter Cleaning Status",
),
HonSensorEntityDescription(
key="lastWorkTime",
name="Last Work Time",
icon="mdi:clock-start",
),
HonSensorEntityDescription(
key="lightStatus",
name="Light Status",
icon="mdi:lightbulb",
),
HonSensorEntityDescription(
key="machMode",
name="Mach Mode",
),
HonSensorEntityDescription(
key="onOffStatus",
name="On / Off Status",
icon="mdi:lightbulb",
),
HonSensorEntityDescription(
key="quickDelayTimeStatus",
name="Quick Delay Time Status",
),
HonSensorEntityDescription(
key="rgbLightColors",
name="RGB Light Color",
icon="mdi:lightbulb",
),
HonSensorEntityDescription(
key="rgbLightStatus",
name="RGB Light Status",
icon="mdi:lightbulb",
),
),
2023-06-10 06:44:19 +02:00
"WC": (
HonSensorEntityDescription(
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
),
HonSensorEntityDescription(
key="humidityZ1",
name="Humidity",
icon="mdi:water-percent",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
HonSensorEntityDescription(
key="humidityZ2",
name="Humidity 2",
icon="mdi:water-percent",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
HonSensorEntityDescription(
key="temp",
name="Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
2023-06-21 00:59:00 +02:00
device_class=SensorDeviceClass.TEMPERATURE,
2023-06-10 06:44:19 +02:00
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="temperature",
),
HonSensorEntityDescription(
key="tempEnv",
name="Room Temperature",
icon="mdi:home-thermometer-outline",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="room_temperature",
),
HonSensorEntityDescription(
key="tempSel",
name="Selected Temperature",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="target_temperature",
),
HonSensorEntityDescription(
key="tempSelZ2",
name="Selected Temperature 2",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="target_temperature",
),
HonSensorEntityDescription(
key="tempZ2",
name="Temperature 2",
icon="mdi:thermometer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
2023-06-21 00:59:00 +02:00
device_class=SensorDeviceClass.TEMPERATURE,
2023-06-10 06:44:19 +02:00
translation_key="temperature",
),
HonSensorEntityDescription(
key="programName",
name="Program",
icon="mdi:play",
device_class=SensorDeviceClass.ENUM,
translation_key="programs_wc",
),
),
2023-06-21 00:59:00 +02:00
"AP": (
HonSensorEntityDescription(
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
),
HonSensorEntityDescription(
key="mainFilterStatus",
name="Main Filter Status",
icon="mdi:air-filter",
translation_key="filter_life",
2023-06-21 00:59:00 +02:00
native_unit_of_measurement=PERCENTAGE,
),
HonSensorEntityDescription(
key="preFilterStatus",
name="Pre Filter Status",
icon="mdi:air-filter",
translation_key="filter_cleaning",
2023-06-21 00:59:00 +02:00
native_unit_of_measurement=PERCENTAGE,
),
HonSensorEntityDescription(
key="totalWorkTime",
name="Total Work Time",
native_unit_of_measurement=UnitOfTime.MINUTES,
device_class=SensorDeviceClass.DURATION,
),
HonSensorEntityDescription(
key="coLevel",
name="CO Level",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.CO,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
),
HonSensorEntityDescription(
key="pm10ValueIndoor",
2023-07-01 01:45:32 +02:00
name="PM 10",
2023-06-21 00:59:00 +02:00
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM10,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
HonSensorEntityDescription(
key="pm2p5ValueIndoor",
2023-07-01 01:45:32 +02:00
name="PM 2.5",
2023-06-21 00:59:00 +02:00
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
HonSensorEntityDescription(
key="vocValueIndoor",
name="VOC",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
2023-07-01 14:24:04 +02:00
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
2023-07-01 01:45:32 +02:00
translation_key="voc",
2023-06-21 00:59:00 +02:00
),
HonSensorEntityDescription(
key="humidityIndoor",
name="Humidity",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
translation_key="humidity",
),
HonSensorEntityDescription(
key="temp",
name="Temperature",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="temperature",
),
HonSensorEntityDescription(
key="windSpeed",
name="Wind Speed",
icon="mdi:fan",
translation_key="fan_speed",
),
2023-06-21 00:59:00 +02:00
HonSensorEntityDescription(
key="airQuality",
name="Air Quality",
icon="mdi:weather-dust",
translation_key="air_quality",
2023-06-21 00:59:00 +02:00
),
),
2023-02-19 02:58:21 +01:00
}
2023-05-07 16:39:45 +02:00
SENSORS["WD"] = unique_entities(SENSORS["WM"], SENSORS["TD"])
2023-02-19 02:58:21 +01:00
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
2023-05-25 01:30:33 +02:00
entities = []
entity: HonSensorEntity | HonConfigSensorEntity
2023-05-25 01:30:33 +02:00
for device in hass.data[DOMAIN][entry.unique_id].appliances:
for description in SENSORS.get(device.appliance_type, []):
2023-05-28 00:30:08 +02:00
if isinstance(description, HonSensorEntityDescription):
2023-06-13 00:14:51 +02:00
if device.get(description.key) is None:
2023-05-28 00:30:08 +02:00
continue
entity = HonSensorEntity(hass, entry, device, description)
elif isinstance(description, HonConfigSensorEntityDescription):
if description.key not in device.available_settings:
continue
entity = HonConfigSensorEntity(hass, entry, device, description)
else:
2023-05-25 01:30:33 +02:00
continue
await entity.coordinator.async_config_entry_first_refresh()
entities.append(entity)
2023-02-19 02:58:21 +01:00
2023-05-25 01:30:33 +02:00
async_add_entities(entities)
2023-02-19 02:58:21 +01:00
class HonSensorEntity(HonEntity, SensorEntity):
2023-05-28 00:30:08 +02:00
entity_description: HonSensorEntityDescription
2023-02-19 02:58:21 +01:00
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
value = self._device.get(self.entity_description.key, "")
if self.entity_description.key == "programName":
if not (options := self._device.settings.get("startProgram.program")):
raise ValueError
self._attr_options = options.values + ["No Program"]
elif self.entity_description.option_list is not None:
self._attr_options = list(self.entity_description.option_list.values())
value = str(get_readable(self.entity_description, value))
if not value and self.entity_description.state_class is not None:
self._attr_native_value = 0
self._attr_native_value = value
2023-06-08 20:01:55 +02:00
if update:
self.async_write_ha_state()
2023-05-28 00:30:08 +02:00
class HonConfigSensorEntity(HonEntity, SensorEntity):
entity_description: HonConfigSensorEntityDescription
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
sensor = self._device.settings.get(self.entity_description.key, None)
value: float | str
2023-05-28 00:30:08 +02:00
if self.entity_description.state_class is not None:
if sensor and sensor.value:
value = (
float(sensor.value)
if "." in str(sensor.value)
else int(sensor.value)
2023-05-28 00:30:08 +02:00
)
else:
value = 0
elif sensor is not None:
value = sensor.value
2023-05-28 00:30:08 +02:00
else:
value = 0
if self.entity_description.option_list is not None and not value == 0:
self._attr_options = list(self.entity_description.option_list.values())
2023-06-13 00:14:51 +02:00
value = get_readable(self.entity_description, value)
self._attr_native_value = value
2023-06-08 20:01:55 +02:00
if update:
self.async_write_ha_state()