Small changes

fixed power switch

Revert "fixed power switch"

This reverts commit a1a2b04444a10c9dba9731ea62571ff20b56ede1.

new HON

switch

stable
This commit is contained in:
Vadym Melnychuk
2026-03-23 12:17:06 +02:00
parent f66bd14ed1
commit e81b1503de
12 changed files with 48 additions and 52 deletions
+6 -5
View File
@@ -5,8 +5,8 @@ from typing import Any
import voluptuous as vol # type: ignore[import-untyped] import voluptuous as vol # type: ignore[import-untyped]
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant as HomeAssistantType
from homeassistant.helpers import config_validation as cv, aiohttp_client from homeassistant.helpers import config_validation as cv, aiohttp_client
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from pyhon import Hon from pyhon import Hon
@@ -53,10 +53,11 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator} hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator}
for platform in PLATFORMS: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
hass.async_create_task( #for platform in PLATFORMS:
hass.config_entries.async_forward_entry_setup(entry, platform) # hass.async_create_task(
) # hass.config_entries.async_forward_entry_setups(entry, platform)
# )
return True return True
+2 -3
View File
@@ -7,9 +7,8 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from .const import DOMAIN from .const import DOMAIN
from .entity import HonEntity from .entity import HonEntity
@@ -356,4 +355,4 @@ class HonBinarySensorEntity(HonEntity, BinarySensorEntity):
== self.entity_description.on_value == self.entity_description.on_value
) )
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
+1 -1
View File
@@ -4,9 +4,9 @@ from pathlib import Path
from homeassistant.components import persistent_notification from homeassistant.components import persistent_notification
from homeassistant.components.button import ButtonEntityDescription, ButtonEntity from homeassistant.components.button import ButtonEntityDescription, ButtonEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant as HomeAssistantType
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from .const import DOMAIN from .const import DOMAIN
+1 -2
View File
@@ -19,9 +19,8 @@ from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
UnitOfTemperature, UnitOfTemperature,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange from pyhon.parameter.range import HonParameterRange
+2 -3
View File
@@ -1,9 +1,8 @@
from typing import Optional, Any from typing import Optional, Any
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
) )
@@ -53,4 +52,4 @@ class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):
@callback @callback
def _handle_coordinator_update(self, update: bool = True) -> None: def _handle_coordinator_update(self, update: bool = True) -> None:
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
+1 -2
View File
@@ -8,9 +8,8 @@ from homeassistant.components.fan import (
FanEntityFeature, FanEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.percentage import ( from homeassistant.util.percentage import (
percentage_to_ranged_value, percentage_to_ranged_value,
ranged_value_to_percentage, ranged_value_to_percentage,
+1 -2
View File
@@ -8,9 +8,8 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange from pyhon.parameter.range import HonParameterRange
+1 -2
View File
@@ -3,9 +3,8 @@ from typing import Any
from homeassistant.components.lock import LockEntity, LockEntityDescription from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.parameter.base import HonParameter from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange from pyhon.parameter.range import HonParameterRange
+3 -4
View File
@@ -9,10 +9,9 @@ from homeassistant.components.number import (
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTime, UnitOfTemperature from homeassistant.const import UnitOfTime, UnitOfTemperature
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange from pyhon.parameter.range import HonParameterRange
@@ -284,7 +283,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
self._attr_native_step = setting.step self._attr_native_step = setting.step
self._attr_native_value = self.native_value self._attr_native_value = self.native_value
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
@property @property
def available(self) -> bool: def available(self) -> bool:
@@ -340,4 +339,4 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
self._attr_native_step = setting.step self._attr_native_step = setting.step
self._attr_native_value = self.native_value self._attr_native_value = self.native_value
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
+9 -11
View File
@@ -6,10 +6,9 @@ from dataclasses import dataclass
from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTemperature, UnitOfTime, REVOLUTIONS_PER_MINUTE from homeassistant.const import UnitOfTemperature, UnitOfTime, REVOLUTIONS_PER_MINUTE
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from . import const from . import const
from .const import DOMAIN from .const import DOMAIN
@@ -187,14 +186,6 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
), ),
), ),
"WH": ( "WH": (
HonSelectEntityDescription(
key="settings.tempSel",
name="Target Temperature",
icon="mdi:thermometer",
unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="target_temperature",
send_key_only=True,
),
HonSelectEntityDescription( HonSelectEntityDescription(
key="settings.machMode", key="settings.machMode",
name="Mode", name="Mode",
@@ -303,9 +294,16 @@ class HonSelectEntity(HonEntity, SelectEntity):
@property @property
def current_option(self) -> str | None: def current_option(self) -> str | None:
key = self.entity_description.key
if self.entity_description.send_key_only:
key = key.split('.')[1]
value = self._device.get(key, "")
value = get_readable(self.entity_description, value)
else:
if not (setting := self._device.settings.get(self.entity_description.key)): if not (setting := self._device.settings.get(self.entity_description.key)):
return None return None
value = get_readable(self.entity_description, setting.value) value = get_readable(self.entity_description, setting.value)
if value not in self._attr_options: if value not in self._attr_options:
return None return None
return str(value) return str(value)
@@ -357,4 +355,4 @@ class HonSelectEntity(HonEntity, SelectEntity):
self._attr_options = self.options self._attr_options = self.options
self._attr_current_option = self.current_option self._attr_current_option = self.current_option
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
+4 -4
View File
@@ -21,10 +21,10 @@ from homeassistant.const import (
UnitOfTime, UnitOfTime,
UnitOfTemperature, UnitOfTemperature,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType from pyhon.attributes import HonAttribute
from . import const from . import const
from .const import DOMAIN from .const import DOMAIN
@@ -903,7 +903,7 @@ class HonSensorEntity(HonEntity, SensorEntity):
self._attr_native_value = 0 self._attr_native_value = 0
self._attr_native_value = value self._attr_native_value = value
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
class HonConfigSensorEntity(HonEntity, SensorEntity): class HonConfigSensorEntity(HonEntity, SensorEntity):
@@ -931,4 +931,4 @@ class HonConfigSensorEntity(HonEntity, SensorEntity):
value = get_readable(self.entity_description, value) value = get_readable(self.entity_description, value)
self._attr_native_value = value self._attr_native_value = value
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
+13 -9
View File
@@ -8,7 +8,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.core import HomeAssistant
from pyhon.parameter.base import HonParameter from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange from pyhon.parameter.range import HonParameterRange
@@ -394,7 +394,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
turn_on_key="startProgram", turn_on_key="startProgram",
turn_off_key="stopProgram", turn_off_key="stopProgram",
translation_key="power", translation_key="power",
only_mandatory_parameters=True, only_mandatory_parameters=False,
on_value=1, on_value=1,
off_value=0, off_value=0,
to_sync=True, to_sync=True,
@@ -421,7 +421,7 @@ SWITCHES["WD"] = unique_entities(SWITCHES["WD"], SWITCHES["TD"])
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
entities = [] entities = []
entity: HonConfigSwitchEntity | HonControlSwitchEntity | HonSwitchEntity entity: HonConfigSwitchEntity | HonControlSwitchEntity | HonSwitchEntity
@@ -494,7 +494,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
def _handle_coordinator_update(self, update: bool = True) -> None: def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_is_on = self.is_on self._attr_is_on = self.is_on
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()
class HonControlSwitchEntity(HonEntity, SwitchEntity): class HonControlSwitchEntity(HonEntity, SwitchEntity):
@@ -512,9 +512,13 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
self._device.sync_command(desc.turn_on_key, "settings", desc.to_sync) self._device.sync_command(desc.turn_on_key, "settings", desc.to_sync)
self.coordinator.async_set_updated_data({}) self.coordinator.async_set_updated_data({})
command = self._device.commands[desc.turn_on_key] command = self._device.commands[desc.turn_on_key]
if self._device.appliance_type == "WH":
command.settings["machMode"].value = self._device.get("machMode", "")
command.settings["tempSel"].value = self._device.get("tempSel", "")
await command.send(desc.only_mandatory_parameters) await command.send(desc.only_mandatory_parameters)
self._device.attributes[desc.key] = desc.on_value self._device.attributes[desc.key] = desc.on_value
self.async_write_ha_state() self.schedule_update_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
desc = self.entity_description desc = self.entity_description
@@ -523,7 +527,7 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
command = self._device.commands[desc.turn_off_key] command = self._device.commands[desc.turn_off_key]
await command.send(desc.only_mandatory_parameters) await command.send(desc.only_mandatory_parameters)
self._device.attributes[desc.key] = desc.off_value self._device.attributes[desc.key] = desc.off_value
self.async_write_ha_state() self.schedule_update_ha_state()
@property @property
def available(self) -> bool: def available(self) -> bool:
@@ -566,7 +570,7 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
return return
setting.value = setting.max if isinstance(setting, HonParameterRange) else "1" setting.value = setting.max if isinstance(setting, HonParameterRange) else "1"
self.coordinator.async_set_updated_data({}) self.coordinator.async_set_updated_data({})
self.async_write_ha_state() self.schedule_update_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
setting = self._device.settings[self.entity_description.key] setting = self._device.settings[self.entity_description.key]
@@ -574,10 +578,10 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
return return
setting.value = setting.min if isinstance(setting, HonParameterRange) else "0" setting.value = setting.min if isinstance(setting, HonParameterRange) else "0"
self.coordinator.async_set_updated_data({}) self.coordinator.async_set_updated_data({})
self.async_write_ha_state() self.schedule_update_ha_state()
@callback @callback
def _handle_coordinator_update(self, update: bool = True) -> None: def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_is_on = self.is_on self._attr_is_on = self.is_on
if update: if update:
self.async_write_ha_state() self.schedule_update_ha_state()