Fix some small bugs

This commit is contained in:
Andre Basche 2023-07-10 00:21:45 +02:00
parent bb700dd2f7
commit c0d25a4efe
4 changed files with 11 additions and 17 deletions

View file

@ -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(

View file

@ -218,6 +218,7 @@ AP_MACH_MODE = {
}
AP_DIFFUSER_LEVEL = {
0: "off",
1: "soft",
2: "mid",
3: "h_biotics",

View file

@ -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

View file

@ -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()