From 155b1ff91a777da222671e305e3e43451dfaea04 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 7 May 2023 16:39:45 +0200 Subject: [PATCH] Add all wm and td sensors to wd --- README.md | 55 +++++++++-- custom_components/hon/binary_sensor.py | 55 +++++------ custom_components/hon/hon.py | 9 ++ custom_components/hon/number.py | 14 +-- custom_components/hon/select.py | 12 +-- custom_components/hon/sensor.py | 127 ++----------------------- custom_components/hon/switch.py | 9 +- 7 files changed, 102 insertions(+), 179 deletions(-) diff --git a/README.md b/README.md index b81d710..2073bf6 100644 --- a/README.md +++ b/README.md @@ -254,13 +254,14 @@ I moved the api related stuff into the package [pyhOn](https://github.com/Andre0 | Energy Label | `lightning-bolt-circle` | `sensor` | `startProgram.energyLabel` | | Program | | `select` | `startProgram.program` | | Steam Type | `weather-dust` | `sensor` | `steamType` | -| Steam level | `smoke` | `sensor` | `steamLevel` | +| Steam level | `smoke` | `sensor` | `startProgram.steamLevel` | | Sterilization | `clock-start` | `switch` | `startProgram.sterilizationStatus` | | Suggested Load | `weight-kilogram` | `sensor` | `startProgram.suggestedLoadD` | | Temperature level | `thermometer` | `number` | `startProgram.tempLevel` | #### Sensors | Name | Icon | Entity | Key | | --- | --- | --- | --- | +| Anti-Crease | | `binary_sensor` | `anticrease` | | Connection | | `binary_sensor` | `attributes.lastConnEvent.category` | | Door | | `binary_sensor` | `doorStatus` | | Dry level | `hair-dryer` | `sensor` | `dryLevel` | @@ -270,42 +271,78 @@ I moved the api related stuff into the package [pyhOn](https://github.com/Andre0 | Program Phase | `washing-machine` | `sensor` | `prPhase` | | Remaining Time | `timer` | `sensor` | `remainingTimeMM` | | Start Time | `clock-start` | `sensor` | `delayTime` | +| Steam level | `smoke` | `sensor` | `steamLevel` | | Temperature level | `thermometer` | `sensor` | `tempLevel` | ### Washer dryer #### Controls | Name | Icon | Entity | Key | | --- | --- | --- | --- | -| Pause Washing Machine | `pause` | `switch` | `pauseProgram` / `resumeProgram` | -| Washing Machine | `washing-machine` | `switch` | `startProgram` / `stopProgram` | +| Pause Washer Dryer | `pause` | `switch` | `pauseProgram` / `resumeProgram` | +| Washer Dryer | `washing-machine` | `switch` | `startProgram` / `stopProgram` | #### Configs | Name | Icon | Entity | Key | | --- | --- | --- | --- | +| Acqua Plus | `water-plus` | `switch` | `startProgram.acquaplus` | +| Anti-Crease | `timer` | `switch` | `startProgram.antiCreaseTime` | +| Anti-Crease | `timer` | `switch` | `startProgram.anticrease` | +| Auto Dose | `cup` | `switch` | `startProgram.autoDetergentStatus` | +| Delay Status | `timer-check` | `switch` | `startProgram.delayStatus` | | Delay Time | `timer-plus` | `number` | `startProgram.delayTime` | +| Dry Time | | `number` | `startProgram.dryTime` | +| Dry Time | `timer` | `select` | `startProgram.dryTimeMM` | +| Dry level | `hair-dryer` | `select` | `startProgram.dryLevel` | +| Energy Label | `lightning-bolt-circle` | `sensor` | `startProgram.energyLabel` | +| Extra Rinse 1 | `numeric-1-box-multiple-outline` | `switch` | `extraRinse1` | +| Extra Rinse 2 | `numeric-2-box-multiple-outline` | `switch` | `extraRinse2` | +| Extra Rinse 3 | `numeric-3-box-multiple-outline` | `switch` | `extraRinse3` | +| Good Night | `weather-night` | `switch` | `goodNight` | +| Keep Fresh | `refresh-circle` | `switch` | `startProgram.autoSoftenerStatus` | +| Liquid Detergent Dose | `cup-water` | `sensor` | `startProgram.liquidDetergentDose` | +| Main Wash Time | `clock-start` | `number` | `startProgram.mainWashTime` | +| Powder Detergent Dose | `cup` | `sensor` | `startProgram.powderDetergentDose` | | Program | | `select` | `startProgram.program` | +| Remaining Time | `timer` | `sensor` | `startProgram.remainingTime` | +| Rinse Iterations | `rotate-right` | `number` | `startProgram.rinseIterations` | +| Soak Prewash Selection | `tshirt-crew` | `switch` | `startProgram.haier_SoakPrewashSelection` | +| Spin speed | `numeric` | `select` | `startProgram.spinSpeed` | +| Steam Level | `weather-dust` | `number` | `startProgram.steamLevel` | +| Steam Type | `weather-dust` | `sensor` | `steamType` | +| Steam level | `smoke` | `sensor` | `startProgram.steamLevel` | +| Sterilization | `clock-start` | `switch` | `startProgram.sterilizationStatus` | +| Suggested Load | `weight-kilogram` | `sensor` | `startProgram.suggestedLoadW` | +| Suggested Load | `weight-kilogram` | `sensor` | `startProgram.suggestedLoadD` | | Suggested weight | `weight-kilogram` | `sensor` | `startProgram.weight` | +| Temperature | `thermometer` | `select` | `startProgram.temp` | +| Temperature level | `thermometer` | `number` | `startProgram.tempLevel` | +| Water hard | `water` | `number` | `startProgram.waterHard` | +| lang | | `number` | `startProgram.lang` | #### Sensors | Name | Icon | Entity | Key | | --- | --- | --- | --- | | Acqua Plus | | `binary_sensor` | `acquaplus` | | Anti-Crease | | `binary_sensor` | `anticrease` | | Current Electricity Used | `lightning-bolt` | `sensor` | `currentElectricityUsed` | -| Current Program | `tumble-dryer` | `sensor` | `prCode` | -| Current Temperature | `thermometer` | `sensor` | `temp` | | Current Water Used | `water` | `sensor` | `currentWaterUsed` | | Dirt level | `liquid-spot` | `sensor` | `dirtyLevel` | +| Door | | `binary_sensor` | `doorStatus` | +| Door Lock | | `binary_sensor` | `doorLockStatus` | | Dry level | `hair-dryer` | `sensor` | `dryLevel` | +| Error | `math-log` | `sensor` | `errors` | | Extra Rinse 1 | | `binary_sensor` | `extraRinse1` | | Extra Rinse 2 | | `binary_sensor` | `extraRinse2` | | Extra Rinse 3 | | `binary_sensor` | `extraRinse3` | | Good Night Mode | | `binary_sensor` | `goodNight` | | Machine Status | `information` | `sensor` | `machMode` | | Pre Wash | | `binary_sensor` | `startProgram.prewash` | +| Program | `tumble-dryer` | `sensor` | `programName` | | Program Phase | `washing-machine` | `sensor` | `prPhase` | | Remaining Time | `timer` | `sensor` | `remainingTimeMM` | | Remote Control | `remote` | `binary_sensor` | `attributes.lastConnEvent.category` | -| Spin Speed | `fast-forward-outline` | `sensor` | `spinSpeed` | +| Spin Speed | `speedometer` | `sensor` | `spinSpeed` | +| Start Time | `clock-start` | `sensor` | `delayTime` | | Steam level | `smoke` | `sensor` | `steamLevel` | +| Temperature level | `thermometer` | `sensor` | `tempLevel` | | Total Power | | `sensor` | `totalElectricityUsed` | | Total Wash Cycle | `counter` | `sensor` | `totalWashCycle` | | Total Water | | `sensor` | `totalWaterUsed` | @@ -346,13 +383,19 @@ I moved the api related stuff into the package [pyhOn](https://github.com/Andre0 #### Sensors | Name | Icon | Entity | Key | | --- | --- | --- | --- | +| Acqua Plus | | `binary_sensor` | `acquaplus` | | Current Electricity Used | `lightning-bolt` | `sensor` | `currentElectricityUsed` | | Current Water Used | `water` | `sensor` | `currentWaterUsed` | | Dirt level | `liquid-spot` | `sensor` | `dirtyLevel` | | Door | | `binary_sensor` | `doorStatus` | | Door Lock | | `binary_sensor` | `doorLockStatus` | | Error | `math-log` | `sensor` | `errors` | +| Extra Rinse 1 | | `binary_sensor` | `extraRinse1` | +| Extra Rinse 2 | | `binary_sensor` | `extraRinse2` | +| Extra Rinse 3 | | `binary_sensor` | `extraRinse3` | +| Good Night Mode | | `binary_sensor` | `goodNight` | | Machine Status | `information` | `sensor` | `machMode` | +| Pre Wash | | `binary_sensor` | `startProgram.prewash` | | Program Phase | `washing-machine` | `sensor` | `prPhase` | | Remaining Time | `timer` | `sensor` | `remainingTimeMM` | | Remote Control | `remote` | `binary_sensor` | `attributes.lastConnEvent.category` | diff --git a/custom_components/hon/binary_sensor.py b/custom_components/hon/binary_sensor.py index 95dde48..e024fd0 100644 --- a/custom_components/hon/binary_sensor.py +++ b/custom_components/hon/binary_sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.binary_sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback from .const import DOMAIN -from .hon import HonCoordinator, HonEntity +from .hon import HonCoordinator, HonEntity, unique_entities _LOGGER = logging.getLogger(__name__) @@ -52,32 +52,6 @@ BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = { on_value="1", translation_key="door_open", ), - ), - "TD": ( - HonBinarySensorEntityDescription( - key="attributes.lastConnEvent.category", - name="Connection", - device_class=BinarySensorDeviceClass.CONNECTIVITY, - on_value="CONNECTED", - translation_key="connection", - ), - HonBinarySensorEntityDescription( - key="doorStatus", - name="Door", - device_class=BinarySensorDeviceClass.DOOR, - on_value="1", - translation_key="door_open", - ), - ), - "WD": ( - HonBinarySensorEntityDescription( - key="attributes.lastConnEvent.category", - name="Remote Control", - device_class=BinarySensorDeviceClass.CONNECTIVITY, - on_value="CONNECTED", - icon="mdi:remote", - translation_key="remote_control", - ), HonBinarySensorEntityDescription( key="startProgram.prewash", name="Pre Wash", translation_key="prewash" ), @@ -96,6 +70,22 @@ BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = { HonBinarySensorEntityDescription( key="acquaplus", name="Acqua Plus", translation_key="acqua_plus" ), + ), + "TD": ( + HonBinarySensorEntityDescription( + key="attributes.lastConnEvent.category", + name="Connection", + device_class=BinarySensorDeviceClass.CONNECTIVITY, + on_value="CONNECTED", + translation_key="connection", + ), + HonBinarySensorEntityDescription( + key="doorStatus", + name="Door", + device_class=BinarySensorDeviceClass.DOOR, + on_value="1", + translation_key="door_open", + ), HonBinarySensorEntityDescription( key="anticrease", name="Anti-Crease", translation_key="anti_crease" ), @@ -208,6 +198,9 @@ BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = { } +BINARY_SENSORS["WD"] = unique_entities(BINARY_SENSORS["WM"], BINARY_SENSORS["TD"]) + + async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] @@ -224,12 +217,8 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non for description in descriptions: if not device.get(description.key): continue - appliances.extend( - [ - HonBinarySensorEntity( - hass, coordinator, entry, device, description - ) - ] + appliances.append( + HonBinarySensorEntity(hass, coordinator, entry, device, description) ) async_add_entities(appliances) diff --git a/custom_components/hon/hon.py b/custom_components/hon/hon.py index f55f761..762bf43 100644 --- a/custom_components/hon/hon.py +++ b/custom_components/hon/hon.py @@ -50,3 +50,12 @@ class HonCoordinator(DataUpdateCoordinator): async def _async_update_data(self): await self._device.update() + + +def unique_entities(base_entities, new_entities): + result = list(base_entities) + existing_entities = [entity.key for entity in base_entities] + for entity in new_entities: + if entity.key not in existing_entities: + result.append(entity) + return tuple(result) diff --git a/custom_components/hon/number.py b/custom_components/hon/number.py index 23f832e..cfd8345 100644 --- a/custom_components/hon/number.py +++ b/custom_components/hon/number.py @@ -15,7 +15,7 @@ from homeassistant.core import callback from homeassistant.helpers.entity import EntityCategory from .const import DOMAIN -from .hon import HonEntity, HonCoordinator +from .hon import HonEntity, HonCoordinator, unique_entities NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { "WM": ( @@ -85,16 +85,6 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { translation_key="dry_time", ), ), - "WD": ( - NumberEntityDescription( - key="startProgram.delayTime", - name="Delay Time", - icon="mdi:timer-plus", - entity_category=EntityCategory.CONFIG, - native_unit_of_measurement=UnitOfTime.MINUTES, - translation_key="delay_time", - ), - ), "OV": ( NumberEntityDescription( key="startProgram.delayTime", @@ -166,6 +156,8 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { ), } +NUMBERS["WD"] = unique_entities(NUMBERS["WM"], NUMBERS["TD"]) + async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: hon: Hon = hass.data[DOMAIN][entry.unique_id] diff --git a/custom_components/hon/select.py b/custom_components/hon/select.py index 66150e2..a27df1d 100644 --- a/custom_components/hon/select.py +++ b/custom_components/hon/select.py @@ -14,7 +14,7 @@ from homeassistant.core import callback from homeassistant.helpers.entity import EntityCategory from .const import DOMAIN -from .hon import HonEntity, HonCoordinator +from .hon import HonEntity, HonCoordinator, unique_entities _LOGGER = logging.getLogger(__name__) @@ -66,14 +66,6 @@ SELECTS = { translation_key="dry_levels", ), ), - "WD": ( - SelectEntityDescription( - key="startProgram.program", - name="Program", - entity_category=EntityCategory.CONFIG, - translation_key="programs_wm", - ), - ), "OV": ( SelectEntityDescription( key="startProgram.program", @@ -114,6 +106,8 @@ SELECTS = { ), } +SELECTS["WD"] = unique_entities(SELECTS["WM"], SELECTS["TD"]) + async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: hon: Hon = hass.data[DOMAIN][entry.unique_id] diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index 83a2244..0dd08dd 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -25,7 +25,7 @@ from homeassistant.const import PERCENTAGE from . import const from .const import DOMAIN -from .hon import HonCoordinator, HonEntity +from .hon import HonCoordinator, HonEntity, unique_entities _LOGGER = logging.getLogger(__name__) @@ -112,7 +112,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { name="Spin Speed", icon="mdi:speedometer", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=UnitOfTime.MINUTES, + native_unit_of_measurement=REVOLUTIONS_PER_MINUTE, translation_key="spin_speed", ), SensorEntityDescription( @@ -238,12 +238,18 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { translation_key="energy_label", ), SensorEntityDescription( - key="steamLevel", + key="startProgram.steamLevel", name="Steam level", icon="mdi:smoke", entity_category=EntityCategory.CONFIG, translation_key="steam_level", ), + SensorEntityDescription( + key="steamLevel", + name="Steam level", + icon="mdi:smoke", + translation_key="steam_level", + ), SensorEntityDescription( key="steamType", name="Steam Type", @@ -251,120 +257,6 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { entity_category=EntityCategory.CONFIG, ), ), - "WD": ( - SensorEntityDescription( - key="totalElectricityUsed", - name="Total Power", - device_class=SensorDeviceClass.ENERGY, - state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, - translation_key="energy_total", - ), - SensorEntityDescription( - key="totalWaterUsed", - name="Total Water", - device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=UnitOfVolume.LITERS, - translation_key="water_total", - ), - SensorEntityDescription( - key="totalWashCycle", - name="Total Wash Cycle", - state_class=SensorStateClass.TOTAL_INCREASING, - icon="mdi:counter", - translation_key="cycles_total", - ), - SensorEntityDescription( - key="currentElectricityUsed", - name="Current Electricity Used", - state_class=SensorStateClass.MEASUREMENT, - device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=UnitOfPower.KILO_WATT, - icon="mdi:lightning-bolt", - translation_key="energy_current", - ), - SensorEntityDescription( - key="currentWaterUsed", - name="Current Water Used", - state_class=SensorStateClass.MEASUREMENT, - icon="mdi:water", - translation_key="water_current", - ), - SensorEntityDescription( - 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( - key="machMode", - name="Machine Status", - icon="mdi:information", - device_class=SensorDeviceClass.ENUM, - translation_key="washing_modes", - options=list(const.MACH_MODE), - ), - SensorEntityDescription( - key="spinSpeed", - name="Spin Speed", - icon="mdi:fast-forward-outline", - state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=REVOLUTIONS_PER_MINUTE, - translation_key="spin_speed", - ), - SensorEntityDescription( - key="remainingTimeMM", - name="Remaining Time", - icon="mdi:timer", - state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=UnitOfTime.MINUTES, - translation_key="remaining_time", - ), - SensorEntityDescription( - key="prCode", - name="Current Program", - icon="mdi:tumble-dryer", - translation_key="programs", - ), - SensorEntityDescription( - key="prPhase", - name="Program Phase", - icon="mdi:washing-machine", - device_class=SensorDeviceClass.ENUM, - translation_key="program_phases_wm", - options=list(const.WASHING_PR_PHASE), - ), - SensorEntityDescription( - key="dryLevel", - name="Dry level", - icon="mdi:hair-dryer", - translation_key="dry_levels", - ), - SensorEntityDescription( - key="dirtyLevel", - name="Dirt level", - icon="mdi:liquid-spot", - translation_key="dirt_level", - ), - SensorEntityDescription( - key="steamLevel", - name="Steam level", - icon="mdi:smoke", - translation_key="steam_level", - ), - SensorEntityDescription( - key="temp", - name="Current Temperature", - icon="mdi:thermometer", - state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=UnitOfTemperature.CELSIUS, - translation_key="temperature", - ), - ), "OV": ( SensorEntityDescription( key="remainingTimeMM", @@ -501,6 +393,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { ), ), } +SENSORS["WD"] = unique_entities(SENSORS["WM"], SENSORS["TD"]) async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index d711a13..a6e6989 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -10,7 +10,7 @@ from pyhon.appliance import HonAppliance from pyhon.parameter.range import HonParameterRange from .const import DOMAIN -from .hon import HonCoordinator, HonEntity +from .hon import HonCoordinator, HonEntity, unique_entities _LOGGER = logging.getLogger(__name__) @@ -168,7 +168,7 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { "WD": ( HonSwitchEntityDescription( key="active", - name="Washing Machine", + name="Washer Dryer", icon="mdi:washing-machine", turn_on_key="startProgram", turn_off_key="stopProgram", @@ -176,7 +176,7 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { ), HonSwitchEntityDescription( key="pause", - name="Pause Washing Machine", + name="Pause Washer Dryer", icon="mdi:pause", turn_on_key="pauseProgram", turn_off_key="resumeProgram", @@ -296,6 +296,9 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { ), } +SWITCHES["WD"] = unique_entities(SWITCHES["WD"], SWITCHES["WM"]) +SWITCHES["WD"] = unique_entities(SWITCHES["WD"], SWITCHES["TD"]) + async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: hon: Hon = hass.data[DOMAIN][entry.unique_id]