From c0d25a4efe0962722527e818973969a4250043bd Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 10 Jul 2023 00:21:45 +0200 Subject: [PATCH] Fix some small bugs --- custom_components/hon/binary_sensor.py | 9 +-------- custom_components/hon/const.py | 1 + custom_components/hon/select.py | 8 +++++--- custom_components/hon/switch.py | 10 ++++------ 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/custom_components/hon/binary_sensor.py b/custom_components/hon/binary_sensor.py index df61f0c..7185231 100644 --- a/custom_components/hon/binary_sensor.py +++ b/custom_components/hon/binary_sensor.py @@ -16,17 +16,10 @@ _LOGGER = logging.getLogger(__name__) @dataclass -class HonBinarySensorEntityDescriptionMixin: +class HonBinarySensorEntityDescription(BinarySensorEntityDescription): on_value: str | float = "" -@dataclass -class HonBinarySensorEntityDescription( - HonBinarySensorEntityDescriptionMixin, BinarySensorEntityDescription -): - pass - - BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = { "WM": ( HonBinarySensorEntityDescription( diff --git a/custom_components/hon/const.py b/custom_components/hon/const.py index fdcc1f2..ad57d8f 100644 --- a/custom_components/hon/const.py +++ b/custom_components/hon/const.py @@ -218,6 +218,7 @@ AP_MACH_MODE = { } AP_DIFFUSER_LEVEL = { + 0: "off", 1: "soft", 2: "mid", 3: "h_biotics", diff --git a/custom_components/hon/select.py b/custom_components/hon/select.py index d86c9e7..d0deabf 100644 --- a/custom_components/hon/select.py +++ b/custom_components/hon/select.py @@ -199,9 +199,11 @@ class HonConfigSelectEntity(HonEntity, SelectEntity): def _option_to_number(self, option: str, values: List[str]): if (options := self.entity_description.option_list) is not None: - return next( - (k for k, v in options.items() if str(k) in values and v == option), - option, + return str( + next( + (k for k, v in options.items() if str(k) in values and v == option), + option, + ) ) return option diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index 4f4c675..c37e299 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -388,7 +388,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity): setting = self._device.settings[f"settings.{self.entity_description.key}"] if type(setting) == HonParameter: return - setting.value = setting.max if isinstance(setting, HonParameterRange) else "1" + setting.value = setting.max if isinstance(setting, HonParameterRange) else 1 self.async_write_ha_state() await self._device.commands["settings"].send() await self.coordinator.async_refresh() @@ -397,7 +397,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity): setting = self._device.settings[f"settings.{self.entity_description.key}"] if type(setting) == HonParameter: return - setting.value = setting.min if isinstance(setting, HonParameterRange) else "0" + setting.value = setting.min if isinstance(setting, HonParameterRange) else 0 self.async_write_ha_state() await self._device.commands["settings"].send() await self.coordinator.async_refresh() @@ -413,8 +413,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity): @callback def _handle_coordinator_update(self, update=True) -> None: - value = self._device.get(self.entity_description.key, 0) - self._attr_state = value == 1 + self._attr_is_on = self.is_on if update: self.async_write_ha_state() @@ -490,7 +489,6 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity): @callback def _handle_coordinator_update(self, update=True) -> None: - value = self._device.settings.get(self.entity_description.key, "0") - self._attr_state = value == "1" + self._attr_is_on = self.is_on if update: self.async_write_ha_state()