From f1e16312ff4701b6059a58f0f23bf824b0e2fe60 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 24 Apr 2023 04:36:14 +0200 Subject: [PATCH] Fix some bugs for hoover appliances, fix #31 --- README.md | 1 + custom_components/hon/manifest.json | 4 ++-- custom_components/hon/number.py | 8 +++++++- custom_components/hon/sensor.py | 15 ++++++++++++--- custom_components/hon/switch.py | 7 +++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9705a44..dfcb877 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ I moved the api related stuff into the package [pyhOn](https://github.com/Andre0 | Name | Icon | Entity | Key | Auto-Translation | | --- | --- | --- | --- | --- | | Anti-Crease | `timer` | `switch` | `startProgram.antiCreaseTime` | ✔ | +| Anti-Crease | `timer` | `switch` | `startProgram.anticrease` | ✔ | | Delay time | `timer-plus` | `number` | `startProgram.delayTime` | ✔ | | Dry Time | | `number` | `startProgram.dryTime` | ✔ | | Dry Time | `timer` | `select` | `startProgram.dryTimeMM` | ✔ | diff --git a/custom_components/hon/manifest.json b/custom_components/hon/manifest.json index ec53fad..08b0332 100644 --- a/custom_components/hon/manifest.json +++ b/custom_components/hon/manifest.json @@ -6,6 +6,6 @@ "documentation": "https://github.com/Andre0512/hon/", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Andre0512/hon/issues", - "requirements": ["pyhOn==0.8.6"], - "version": "0.7.0-beta.5" + "requirements": ["pyhOn==0.9.0"], + "version": "0.7.0-beta.6" } diff --git a/custom_components/hon/number.py b/custom_components/hon/number.py index ee14e91..c80f5fe 100644 --- a/custom_components/hon/number.py +++ b/custom_components/hon/number.py @@ -1,6 +1,8 @@ from __future__ import annotations from pyhon import Hon +from pyhon.parameter.base import HonParameter +from pyhon.parameter.fixed import HonParameterFixed from pyhon.parameter.range import HonParameterRange from homeassistant.components.number import ( @@ -179,7 +181,11 @@ class HonNumberEntity(HonEntity, NumberEntity): return self._device.get(self.entity_description.key) async def async_set_native_value(self, value: float) -> None: - self._device.settings[self.entity_description.key].value = value + setting = self._device.settings[self.entity_description.key] + if not ( + isinstance(setting, HonParameter) or isinstance(setting, HonParameterFixed) + ): + setting.value = value await self.coordinator.async_refresh() @callback diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index 295f225..eedcdfd 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -182,6 +182,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { 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", ), @@ -444,7 +445,9 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non if descriptions := SENSORS.get(device.appliance_type): for description in descriptions: - if not device.get(description.key): + if not device.get(description.key) and not device.settings.get( + description.key + ): _LOGGER.warning( "[%s] Can't setup %s", device.appliance_type, description.key ) @@ -467,9 +470,15 @@ class HonSensorEntity(HonEntity, SensorEntity): @property def native_value(self) -> StateType: - return self._device.get(self.entity_description.key, "") + value = self._device.get(self.entity_description.key, "") + if not value and self.entity_description.state_class is not None: + return 0 + return value @callback def _handle_coordinator_update(self): - self._attr_native_value = self._device.get(self.entity_description.key, "") + value = self._device.get(self.entity_description.key, "") + if not value and self.entity_description.state_class is not None: + self._attr_native_value = 0 + self._attr_native_value = value self.async_write_ha_state() diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index 277e5ab..7b76dc9 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -97,6 +97,13 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { icon="mdi:timer", translation_key="anti_crease", ), + HonSwitchEntityDescription( + key="startProgram.anticrease", + name="Anti-Crease", + entity_category=EntityCategory.CONFIG, + icon="mdi:timer", + translation_key="anti_crease", + ), ), "OV": ( HonSwitchEntityDescription(