diff --git a/custom_components/hon/__init__.py b/custom_components/hon/__init__.py index 1e38a2d..81b81bb 100644 --- a/custom_components/hon/__init__.py +++ b/custom_components/hon/__init__.py @@ -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 diff --git a/custom_components/hon/binary_sensor.py b/custom_components/hon/binary_sensor.py index 4f85635..23de62e 100644 --- a/custom_components/hon/binary_sensor.py +++ b/custom_components/hon/binary_sensor.py @@ -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() diff --git a/custom_components/hon/button.py b/custom_components/hon/button.py index ce0f548..03e4f5e 100644 --- a/custom_components/hon/button.py +++ b/custom_components/hon/button.py @@ -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 diff --git a/custom_components/hon/climate.py b/custom_components/hon/climate.py index f3ce937..5f574a0 100644 --- a/custom_components/hon/climate.py +++ b/custom_components/hon/climate.py @@ -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 diff --git a/custom_components/hon/entity.py b/custom_components/hon/entity.py index a597052..154ce32 100644 --- a/custom_components/hon/entity.py +++ b/custom_components/hon/entity.py @@ -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() diff --git a/custom_components/hon/fan.py b/custom_components/hon/fan.py index a07a08f..2432b83 100644 --- a/custom_components/hon/fan.py +++ b/custom_components/hon/fan.py @@ -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, diff --git a/custom_components/hon/light.py b/custom_components/hon/light.py index d38a994..840c5d6 100644 --- a/custom_components/hon/light.py +++ b/custom_components/hon/light.py @@ -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 diff --git a/custom_components/hon/lock.py b/custom_components/hon/lock.py index 1ecb744..d098ab0 100644 --- a/custom_components/hon/lock.py +++ b/custom_components/hon/lock.py @@ -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 diff --git a/custom_components/hon/number.py b/custom_components/hon/number.py index 5864c36..9edf360 100644 --- a/custom_components/hon/number.py +++ b/custom_components/hon/number.py @@ -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() diff --git a/custom_components/hon/select.py b/custom_components/hon/select.py index 90fd98a..7eb5bbf 100644 --- a/custom_components/hon/select.py +++ b/custom_components/hon/select.py @@ -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() diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index cc741bb..20ae360 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -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() diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index 209d069..94ff523 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -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()