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

View file

@ -5,8 +5,8 @@ from typing import Any
import voluptuous as vol # type: ignore[import-untyped]
from homeassistant.config_entries import ConfigEntry
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.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from pyhon import Hon
@ -53,10 +53,11 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator}
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
#for platform in PLATFORMS:
# hass.async_create_task(
# hass.config_entries.async_forward_entry_setups(entry, platform)
# )
return True

View file

@ -7,9 +7,8 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity,
)
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.typing import HomeAssistantType
from .const import DOMAIN
from .entity import HonEntity
@ -356,4 +355,4 @@ class HonBinarySensorEntity(HonEntity, BinarySensorEntity):
== self.entity_description.on_value
)
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

View file

@ -4,9 +4,9 @@ from pathlib import Path
from homeassistant.components import persistent_notification
from homeassistant.components.button import ButtonEntityDescription, ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant as HomeAssistantType
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from .const import DOMAIN

View file

@ -19,9 +19,8 @@ from homeassistant.const import (
ATTR_TEMPERATURE,
UnitOfTemperature,
)
from homeassistant.core import callback
from homeassistant.core import HomeAssistant as HomeAssistantType, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

View file

@ -1,9 +1,8 @@
from typing import Optional, Any
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.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
)
@ -53,4 +52,4 @@ class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

View file

@ -8,9 +8,8 @@ from homeassistant.components.fan import (
FanEntityFeature,
)
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.typing import HomeAssistantType
from homeassistant.util.percentage import (
percentage_to_ranged_value,
ranged_value_to_percentage,

View file

@ -8,9 +8,8 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS,
)
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.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

View file

@ -3,9 +3,8 @@ from typing import Any
from homeassistant.components.lock import LockEntity, LockEntityDescription
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.typing import HomeAssistantType
from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange

View file

@ -9,10 +9,9 @@ from homeassistant.components.number import (
)
from homeassistant.config_entries import ConfigEntry
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_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange
@ -284,7 +283,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
self._attr_native_step = setting.step
self._attr_native_value = self.native_value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
@property
def available(self) -> bool:
@ -340,4 +339,4 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
self._attr_native_step = setting.step
self._attr_native_value = self.native_value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

View file

@ -6,10 +6,9 @@ from dataclasses import dataclass
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
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_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from . import const
from .const import DOMAIN
@ -187,14 +186,6 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
),
),
"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(
key="settings.machMode",
name="Mode",
@ -202,7 +193,7 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
icon="mdi:information",
option_list=const.WH_MACH_MODE,
translation_key="mach_modes_wh",
),
),
),
"FRE": (
HonConfigSelectEntityDescription(
@ -303,9 +294,16 @@ class HonSelectEntity(HonEntity, SelectEntity):
@property
def current_option(self) -> str | None:
if not (setting := self._device.settings.get(self.entity_description.key)):
return None
value = get_readable(self.entity_description, setting.value)
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)):
return None
value = get_readable(self.entity_description, setting.value)
if value not in self._attr_options:
return None
return str(value)
@ -357,4 +355,4 @@ class HonSelectEntity(HonEntity, SelectEntity):
self._attr_options = self.options
self._attr_current_option = self.current_option
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

View file

@ -21,10 +21,10 @@ 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_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.attributes import HonAttribute
from . import const
from .const import DOMAIN
@ -903,7 +903,7 @@ class HonSensorEntity(HonEntity, SensorEntity):
self._attr_native_value = 0
self._attr_native_value = value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
class HonConfigSensorEntity(HonEntity, SensorEntity):
@ -931,4 +931,4 @@ class HonConfigSensorEntity(HonEntity, SensorEntity):
value = get_readable(self.entity_description, value)
self._attr_native_value = value
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()

View file

@ -8,7 +8,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory
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.range import HonParameterRange
@ -394,7 +394,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
turn_on_key="startProgram",
turn_off_key="stopProgram",
translation_key="power",
only_mandatory_parameters=True,
only_mandatory_parameters=False,
on_value=1,
off_value=0,
to_sync=True,
@ -421,7 +421,7 @@ SWITCHES["WD"] = unique_entities(SWITCHES["WD"], SWITCHES["TD"])
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
entity: HonConfigSwitchEntity | HonControlSwitchEntity | HonSwitchEntity
@ -494,7 +494,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_is_on = self.is_on
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
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.coordinator.async_set_updated_data({})
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)
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:
desc = self.entity_description
@ -523,7 +527,7 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
command = self._device.commands[desc.turn_off_key]
await command.send(desc.only_mandatory_parameters)
self._device.attributes[desc.key] = desc.off_value
self.async_write_ha_state()
self.schedule_update_ha_state()
@property
def available(self) -> bool:
@ -566,7 +570,7 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
return
setting.value = setting.max if isinstance(setting, HonParameterRange) else "1"
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:
setting = self._device.settings[self.entity_description.key]
@ -574,10 +578,10 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
return
setting.value = setting.min if isinstance(setting, HonParameterRange) else "0"
self.coordinator.async_set_updated_data({})
self.async_write_ha_state()
self.schedule_update_ha_state()
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
self._attr_is_on = self.is_on
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()