mirror of
https://github.com/Andre0512/hon.git
synced 2024-12-22 18:55:31 +00:00
Fix some small bugs
This commit is contained in:
parent
bb700dd2f7
commit
c0d25a4efe
|
@ -16,17 +16,10 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HonBinarySensorEntityDescriptionMixin:
|
class HonBinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||||
on_value: str | float = ""
|
on_value: str | float = ""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HonBinarySensorEntityDescription(
|
|
||||||
HonBinarySensorEntityDescriptionMixin, BinarySensorEntityDescription
|
|
||||||
):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = {
|
BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = {
|
||||||
"WM": (
|
"WM": (
|
||||||
HonBinarySensorEntityDescription(
|
HonBinarySensorEntityDescription(
|
||||||
|
|
|
@ -218,6 +218,7 @@ AP_MACH_MODE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
AP_DIFFUSER_LEVEL = {
|
AP_DIFFUSER_LEVEL = {
|
||||||
|
0: "off",
|
||||||
1: "soft",
|
1: "soft",
|
||||||
2: "mid",
|
2: "mid",
|
||||||
3: "h_biotics",
|
3: "h_biotics",
|
||||||
|
|
|
@ -199,10 +199,12 @@ class HonConfigSelectEntity(HonEntity, SelectEntity):
|
||||||
|
|
||||||
def _option_to_number(self, option: str, values: List[str]):
|
def _option_to_number(self, option: str, values: List[str]):
|
||||||
if (options := self.entity_description.option_list) is not None:
|
if (options := self.entity_description.option_list) is not None:
|
||||||
return next(
|
return str(
|
||||||
|
next(
|
||||||
(k for k, v in options.items() if str(k) in values and v == option),
|
(k for k, v in options.items() if str(k) in values and v == option),
|
||||||
option,
|
option,
|
||||||
)
|
)
|
||||||
|
)
|
||||||
return option
|
return option
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
|
|
|
@ -388,7 +388,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
||||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
||||||
if type(setting) == HonParameter:
|
if type(setting) == HonParameter:
|
||||||
return
|
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()
|
self.async_write_ha_state()
|
||||||
await self._device.commands["settings"].send()
|
await self._device.commands["settings"].send()
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
@ -397,7 +397,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
||||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
||||||
if type(setting) == HonParameter:
|
if type(setting) == HonParameter:
|
||||||
return
|
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()
|
self.async_write_ha_state()
|
||||||
await self._device.commands["settings"].send()
|
await self._device.commands["settings"].send()
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
@ -413,8 +413,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self, update=True) -> None:
|
def _handle_coordinator_update(self, update=True) -> None:
|
||||||
value = self._device.get(self.entity_description.key, 0)
|
self._attr_is_on = self.is_on
|
||||||
self._attr_state = value == 1
|
|
||||||
if update:
|
if update:
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@ -490,7 +489,6 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self, update=True) -> None:
|
def _handle_coordinator_update(self, update=True) -> None:
|
||||||
value = self._device.settings.get(self.entity_description.key, "0")
|
self._attr_is_on = self.is_on
|
||||||
self._attr_state = value == "1"
|
|
||||||
if update:
|
if update:
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
Loading…
Reference in a new issue