mirror of
https://github.com/Andre0512/hon.git
synced 2025-05-13 06:34:22 -04:00
Refactor hon entities
This commit is contained in:
parent
696dc136eb
commit
a8762367ed
8 changed files with 382 additions and 369 deletions
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
|
@ -20,7 +21,6 @@ from homeassistant.const import (
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import const
|
||||
from .const import DOMAIN
|
||||
from .hon import HonEntity, unique_entities
|
||||
|
@ -28,9 +28,19 @@ from .hon import HonEntity, unique_entities
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class HonConfigSensorEntityDescription(SensorEntityDescription):
|
||||
entity_category: EntityCategory = EntityCategory.CONFIG
|
||||
|
||||
|
||||
@dataclass
|
||||
class HonSensorEntityDescription(SensorEntityDescription):
|
||||
pass
|
||||
|
||||
|
||||
SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
||||
"WM": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="prPhase",
|
||||
name="Program Phase",
|
||||
icon="mdi:washing-machine",
|
||||
|
@ -38,7 +48,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="program_phases_wm",
|
||||
options=list(const.WASHING_PR_PHASE),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="totalElectricityUsed",
|
||||
name="Total Power",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
|
@ -46,7 +56,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
translation_key="energy_total",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="totalWaterUsed",
|
||||
name="Total Water",
|
||||
device_class=SensorDeviceClass.WATER,
|
||||
|
@ -54,14 +64,14 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfVolume.LITERS,
|
||||
translation_key="water_total",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="totalWashCycle",
|
||||
name="Total Wash Cycle",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:counter",
|
||||
translation_key="cycles_total",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="currentElectricityUsed",
|
||||
name="Current Electricity Used",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -70,23 +80,22 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
icon="mdi:lightning-bolt",
|
||||
translation_key="energy_current",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="currentWaterUsed",
|
||||
name="Current Water Used",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
icon="mdi:water",
|
||||
translation_key="water_current",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.weight",
|
||||
name="Suggested weight",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
|
||||
icon="mdi:weight-kilogram",
|
||||
translation_key="suggested_load",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="machMode",
|
||||
name="Machine Status",
|
||||
icon="mdi:information",
|
||||
|
@ -94,10 +103,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="washing_modes",
|
||||
options=list(const.MACH_MODE),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="remainingTimeMM",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
|
@ -105,7 +114,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="spinSpeed",
|
||||
name="Spin Speed",
|
||||
icon="mdi:speedometer",
|
||||
|
@ -113,53 +122,48 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
|
||||
translation_key="spin_speed",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.energyLabel",
|
||||
name="Energy Label",
|
||||
icon="mdi:lightning-bolt-circle",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="energy_label",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.liquidDetergentDose",
|
||||
name="Liquid Detergent Dose",
|
||||
icon="mdi:cup-water",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="det_liquid",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.powderDetergentDose",
|
||||
name="Powder Detergent Dose",
|
||||
icon="mdi:cup",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="det_dust",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.remainingTime",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="dirtyLevel",
|
||||
name="Dirt level",
|
||||
icon="mdi:liquid-spot",
|
||||
translation_key="dirt_level",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.suggestedLoadW",
|
||||
name="Suggested Load",
|
||||
icon="mdi:weight-kilogram",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
|
||||
translation_key="suggested_load",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="temp",
|
||||
name="Current Temperature",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -169,7 +173,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
),
|
||||
"TD": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="machMode",
|
||||
name="Machine Status",
|
||||
icon="mdi:information",
|
||||
|
@ -177,10 +181,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="washing_modes",
|
||||
options=list(const.MACH_MODE),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="remainingTimeMM",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
|
@ -188,7 +192,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="delayTime",
|
||||
name="Start Time",
|
||||
icon="mdi:clock-start",
|
||||
|
@ -196,7 +200,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="delay_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="programName",
|
||||
name="Program",
|
||||
icon="mdi:tumble-dryer",
|
||||
|
@ -204,7 +208,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="programs_td",
|
||||
options=const.PROGRAMS_TD,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="prPhase",
|
||||
name="Program Phase",
|
||||
icon="mdi:washing-machine",
|
||||
|
@ -212,7 +216,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="program_phases_td",
|
||||
options=list(const.TUMBLE_DRYER_PR_PHASE),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="dryLevel",
|
||||
name="Dry level",
|
||||
icon="mdi:hair-dryer",
|
||||
|
@ -220,58 +224,54 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="dry_levels",
|
||||
options=list(const.TUMBLE_DRYER_DRY_LEVEL),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempLevel",
|
||||
name="Temperature level",
|
||||
icon="mdi:thermometer",
|
||||
translation_key="tumbledryertemplevel",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.suggestedLoadD",
|
||||
name="Suggested Load",
|
||||
icon="mdi:weight-kilogram",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfMass.KILOGRAMS,
|
||||
translation_key="suggested_load",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.energyLabel",
|
||||
name="Energy Label",
|
||||
icon="mdi:lightning-bolt-circle",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="energy_label",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.steamLevel",
|
||||
name="Steam level",
|
||||
icon="mdi:smoke",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="steam_level",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="steamLevel",
|
||||
name="Steam level",
|
||||
icon="mdi:smoke",
|
||||
translation_key="steam_level",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="steamType",
|
||||
name="Steam Type",
|
||||
icon="mdi:weather-dust",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
),
|
||||
"OV": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="remainingTimeMM",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="delayTime",
|
||||
name="Start Time",
|
||||
icon="mdi:clock-start",
|
||||
|
@ -279,13 +279,13 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="delay_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="temp",
|
||||
name="Temperature",
|
||||
icon="mdi:thermometer",
|
||||
translation_key="temperature",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempSel",
|
||||
name="Temperature Selected",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -293,14 +293,14 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
),
|
||||
"IH": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="remainingTimeMM",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="temp",
|
||||
name="Temperature",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -308,10 +308,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
translation_key="temperature",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="power",
|
||||
name="Power",
|
||||
icon="mdi:lightning-bolt",
|
||||
|
@ -320,57 +320,51 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
),
|
||||
"DW": (
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.ecoIndex",
|
||||
name="Eco Index",
|
||||
icon="mdi:sprout",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.waterEfficiency",
|
||||
name="Water Efficiency",
|
||||
icon="mdi:water",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="water_efficiency",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.waterSaving",
|
||||
name="Water Saving",
|
||||
icon="mdi:water-percent",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="water_saving",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.temp",
|
||||
name="Temperature",
|
||||
icon="mdi:thermometer",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="temperature",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.energyLabel",
|
||||
name="Energy Label",
|
||||
icon="mdi:lightning-bolt-circle",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="energy_label",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonConfigSensorEntityDescription(
|
||||
key="startProgram.remainingTime",
|
||||
name="Time",
|
||||
icon="mdi:timer",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="duration",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="machMode",
|
||||
name="Machine Status",
|
||||
icon="mdi:information",
|
||||
|
@ -378,10 +372,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
translation_key="washing_modes",
|
||||
options=list(const.MACH_MODE),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="remainingTimeMM",
|
||||
name="Remaining Time",
|
||||
icon="mdi:timer",
|
||||
|
@ -389,7 +383,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
translation_key="remaining_time",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="prPhase",
|
||||
name="Program Phase",
|
||||
icon="mdi:washing-machine",
|
||||
|
@ -399,7 +393,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
),
|
||||
"AC": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempAirOutdoor",
|
||||
name="Air Temperature Outdoor",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -407,7 +401,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempCoilerIndoor",
|
||||
name="Coiler Temperature Indoor",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -415,7 +409,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempCoilerOutdoor",
|
||||
name="Coiler Temperature Outside",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -423,7 +417,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempDefrostOutdoor",
|
||||
name="Defrost Temperature Outdoor",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -431,7 +425,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempInAirOutdoor",
|
||||
name="In Air Temperature Outdoor",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -439,7 +433,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempIndoor",
|
||||
name="Indoor Temperature",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -447,7 +441,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempOutdoor",
|
||||
name="Outdoor Temperature",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -455,7 +449,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempSel",
|
||||
name="Selected Temperature",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -465,7 +459,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
),
|
||||
"REF": (
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="humidityEnv",
|
||||
name="Room Humidity",
|
||||
icon="mdi:water-percent",
|
||||
|
@ -474,7 +468,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
state_class=SensorStateClass.MEASUREMENT,
|
||||
translation_key="humidity",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempEnv",
|
||||
name="Room Temperature",
|
||||
icon="mdi:home-thermometer-outline",
|
||||
|
@ -483,7 +477,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
translation_key="room_temperature",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempZ1",
|
||||
name="Temperature Fridge",
|
||||
icon="mdi:thermometer",
|
||||
|
@ -492,7 +486,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
translation_key="fridge_temp",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="tempZ2",
|
||||
name="Temperature Freezer",
|
||||
icon="mdi:snowflake-thermometer",
|
||||
|
@ -501,7 +495,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
translation_key="freezer_temp",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HonSensorEntityDescription(
|
||||
key="errors", name="Error", icon="mdi:math-log", translation_key="errors"
|
||||
),
|
||||
),
|
||||
|
@ -513,11 +507,16 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
entities = []
|
||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
||||
for description in SENSORS.get(device.appliance_type, []):
|
||||
if not device.get(description.key) and not device.settings.get(
|
||||
description.key
|
||||
):
|
||||
if isinstance(description, HonSensorEntityDescription):
|
||||
if not device.get(description.key):
|
||||
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:
|
||||
continue
|
||||
entity = HonSensorEntity(hass, entry, device, description)
|
||||
await entity.coordinator.async_config_entry_first_refresh()
|
||||
entities.append(entity)
|
||||
|
||||
|
@ -525,18 +524,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
|
||||
|
||||
class HonSensorEntity(HonEntity, SensorEntity):
|
||||
def __init__(self, hass, entry, device, description) -> None:
|
||||
super().__init__(hass, entry, device)
|
||||
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{super().unique_id}{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
value = self._device.get(self.entity_description.key, "")
|
||||
if not value and self.entity_description.state_class is not None:
|
||||
return 0
|
||||
return value
|
||||
entity_description: HonSensorEntityDescription
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
|
@ -545,3 +533,22 @@ class HonSensorEntity(HonEntity, SensorEntity):
|
|||
self._attr_native_value = 0
|
||||
self._attr_native_value = value
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
class HonConfigSensorEntity(HonEntity, SensorEntity):
|
||||
entity_description: HonConfigSensorEntityDescription
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
value = self._device.settings.get(self.entity_description.key, None)
|
||||
if self.entity_description.state_class is not None:
|
||||
if value and value.value:
|
||||
print(value.value, type(value.value))
|
||||
self._attr_native_value = (
|
||||
float(value.value) if "." in str(value.value) else int(value.value)
|
||||
)
|
||||
else:
|
||||
self._attr_native_value = 0
|
||||
else:
|
||||
self._attr_native_value = value.value
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue