Compare commits

...

14 Commits

Author SHA1 Message Date
Niek Schoemaker 8e8a7b12dc Change async_write_ha_state to schedule_update_ha_state in entity.py 2025-01-16 13:53:32 +01:00
Niek Schoemaker 3325bb27b9 Correctly call on_update function with hass.add_job so it runs on the correct thread 2025-01-16 13:52:48 +01:00
Niek Schoemaker 6ffb7a4901 Remove deprecated typing and fix thread safety issue 2024-12-29 21:13:48 +01:00
Andre Basche 70eb6c0111 Update manifest.json 2024-08-14 22:51:18 +02:00
Andre Basche 9bab35f8c4 Update manifest.json 2024-08-14 22:46:43 +02:00
zawadzkipiter 39fc30c95e Update pyhon to 0.17.5
fix for HA "Can't login" based on:
https://github.com/Andre0512/pyhOn/pull/29
2024-08-14 22:46:10 +02:00
Andre Basche 6906e751b1 Bump version 2024-04-09 22:49:49 +02:00
Andre Basche 6d2a6ce2e9 Fix unit of current elecricity #158 2024-03-30 23:16:54 +01:00
Andre Basche 0e166f3c66 Bump version 2024-03-30 20:26:08 +01:00
Andre Basche 54dd406ec2 Fix checks 2024-03-30 20:25:08 +01:00
Andre Basche a746584833 Fix unkown for 0 in number entity 2024-03-30 20:23:39 +01:00
Andre Basche 36aed2e6ea Fix update entity when changing config 2024-03-30 19:47:46 +01:00
Andre Basche 510c10bd9f Improve device info 2024-03-30 19:46:24 +01:00
Andre Basche 09189ff0f8 Change to new climate enity style, fix #165 2024-03-30 17:29:25 +01:00
14 changed files with 96 additions and 80 deletions
+5 -5
View File
@@ -6,8 +6,8 @@ import voluptuous as vol # type: ignore[import-untyped]
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
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.core import HomeAssistant
from pyhon import Hon
from .const import DOMAIN, PLATFORMS, MOBILE_ID, CONF_REFRESH_TOKEN
@@ -27,7 +27,7 @@ CONFIG_SCHEMA = vol.Schema(
)
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
session = aiohttp_client.async_get_clientsession(hass)
if (config_dir := hass.config.config_dir) is None:
raise ValueError("Missing Config Dir")
@@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
password=entry.data[CONF_PASSWORD],
mobile_id=MOBILE_ID,
session=session,
# test_data_path=Path(config_dir),
test_data_path=Path(config_dir),
refresh_token=entry.data.get(CONF_REFRESH_TOKEN, ""),
).create()
@@ -48,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
coordinator: DataUpdateCoordinator[dict[str, Any]] = DataUpdateCoordinator(
hass, _LOGGER, name=DOMAIN
)
hon.subscribe_updates(coordinator.async_set_updated_data)
hon.subscribe_updates(lambda data: hass.add_job(coordinator.async_set_updated_data, data))
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator}
@@ -60,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
return True
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
refresh_token = hass.data[DOMAIN][entry.unique_id]["hon"].api.auth.refresh_token
hass.config_entries.async_update_entry(
+3 -4
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 callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from .const import DOMAIN
from .entity import HonEntity
@@ -317,7 +316,7 @@ BINARY_SENSORS["WD"] = unique_entities(BINARY_SENSORS["WM"], BINARY_SENSORS["TD"
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
@@ -346,4 +345,4 @@ class HonBinarySensorEntity(HonEntity, BinarySensorEntity):
== self.entity_description.on_value
)
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
+4 -4
View File
@@ -6,7 +6,7 @@ from homeassistant.components.button import ButtonEntityDescription, ButtonEntit
from homeassistant.config_entries import ConfigEntry
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.appliance import HonAppliance
from .const import DOMAIN
@@ -56,7 +56,7 @@ BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = {
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities: list[HonButtonType] = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
@@ -88,7 +88,7 @@ class HonButtonEntity(HonEntity, ButtonEntity):
class HonDeviceInfo(HonEntity, ButtonEntity):
def __init__(
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
) -> None:
super().__init__(hass, entry, device)
@@ -108,7 +108,7 @@ class HonDeviceInfo(HonEntity, ButtonEntity):
class HonDataArchive(HonEntity, ButtonEntity):
def __init__(
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
) -> None:
super().__init__(hass, entry, device)
+27 -9
View File
@@ -1,3 +1,4 @@
import asyncio
import logging
from dataclasses import dataclass
from typing import Any
@@ -19,9 +20,8 @@ from homeassistant.const import (
ATTR_TEMPERATURE,
UnitOfTemperature,
)
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange
@@ -104,7 +104,7 @@ CLIMATES: dict[
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
entity: HonClimateEntity | HonACClimateEntity
@@ -126,10 +126,11 @@ async def async_setup_entry(
class HonACClimateEntity(HonEntity, ClimateEntity):
entity_description: HonACClimateEntityDescription
_enable_turn_on_off_backwards_compatibility = False
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonACClimateEntityDescription,
@@ -211,6 +212,14 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
await self._device.commands["settings"].send()
self.async_write_ha_state()
async def async_turn_on(self, **kwargs: Any) -> None:
await self._device.commands["startProgram"].send()
self._device.sync_command("startProgram", "settings")
async def async_turn_off(self, **kwargs: Any) -> None:
await self._device.commands["stopProgram"].send()
self._device.sync_command("stopProgram", "settings")
@property
def preset_mode(self) -> str | None:
"""Return the current Preset for this channel."""
@@ -223,7 +232,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
self._device.sync_command("startProgram", "settings")
self._set_temperature_bound()
self._handle_coordinator_update(update=False)
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
self._attr_preset_mode = preset_mode
await self._device.commands["startProgram"].send()
self.async_write_ha_state()
@@ -281,15 +290,16 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
class HonClimateEntity(HonEntity, ClimateEntity):
entity_description: HonClimateEntityDescription
_enable_turn_on_off_backwards_compatibility = False
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonClimateEntityDescription,
@@ -363,6 +373,14 @@ class HonClimateEntity(HonEntity, ClimateEntity):
self._attr_hvac_mode = hvac_mode
self.async_write_ha_state()
async def async_turn_on(self) -> None:
"""Set the HVAC State to on."""
await self._device.commands["startProgram"].send()
async def async_turn_off(self) -> None:
"""Set the HVAC State to off."""
await self._device.commands["stopProgram"].send()
@property
def preset_mode(self) -> str | None:
"""Return the current Preset for this channel."""
@@ -390,7 +408,7 @@ class HonClimateEntity(HonEntity, ClimateEntity):
self._device.sync_command(command, "settings")
self._set_temperature_bound()
self._attr_preset_mode = preset_mode
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
await self._device.commands[command].send()
self.async_write_ha_state()
@@ -405,4 +423,4 @@ class HonClimateEntity(HonEntity, ClimateEntity):
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
+6 -5
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 callback, HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
)
@@ -20,7 +19,7 @@ class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: Optional[HonEntityDescription] = None,
@@ -42,13 +41,15 @@ class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):
def device_info(self) -> DeviceInfo:
return DeviceInfo(
identifiers={(DOMAIN, self._device.unique_id)},
manufacturer=self._device.get("brand", ""),
manufacturer=self._device.get("brand", "").capitalize(),
name=self._device.nick_name,
model=self._device.model_name,
sw_version=self._device.get("fwVersion", ""),
hw_version=f"{self._device.appliance_type}{self._device.model_id}",
serial_number=self._device.get("serialNumber", ""),
)
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
+4 -5
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 callback, HomeAssistant
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,
@@ -36,7 +35,7 @@ FANS: dict[str, tuple[FanEntityDescription, ...]] = {
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
@@ -56,7 +55,7 @@ class HonFanEntity(HonEntity, FanEntity):
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: FanEntityDescription,
@@ -125,7 +124,7 @@ class HonFanEntity(HonEntity, FanEntity):
)
self._attr_percentage = self.percentage
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
@property
def available(self) -> bool:
+4 -5
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 callback, HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange
@@ -53,7 +52,7 @@ LIGHTS: dict[str, tuple[LightEntityDescription, ...]] = {
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
@@ -73,7 +72,7 @@ class HonLightEntity(HonEntity, LightEntity):
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: LightEntityDescription,
@@ -136,7 +135,7 @@ class HonLightEntity(HonEntity, LightEntity):
self._attr_is_on = self.is_on
self._attr_brightness = self.brightness
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
@property
def available(self) -> bool:
+4 -5
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 callback, HomeAssistant
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
@@ -26,7 +25,7 @@ LOCKS: dict[str, tuple[LockEntityDescription, ...]] = {
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
entities = []
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
@@ -58,7 +57,7 @@ class HonLockEntity(HonEntity, LockEntity):
setting.value = setting.max if isinstance(setting, HonParameterRange) else 1
self.async_write_ha_state()
await self._device.commands["settings"].send()
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock method."""
@@ -68,7 +67,7 @@ class HonLockEntity(HonEntity, LockEntity):
setting.value = setting.min if isinstance(setting, HonParameterRange) else 0
self.async_write_ha_state()
await self._device.commands["settings"].send()
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@property
def available(self) -> bool:
+2 -2
View File
@@ -9,7 +9,7 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/Andre0512/hon/issues",
"requirements": [
"pyhOn==0.17.3"
"pyhOn==0.17.5"
],
"version": "0.14.0-beta.5"
"version": "0.14.0"
}
+9 -10
View File
@@ -8,10 +8,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 callback, HomeAssistant
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
@@ -207,7 +206,7 @@ NUMBERS["WD"] = unique_entities(NUMBERS["WM"], NUMBERS["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: HonNumberEntity | HonConfigNumberEntity
@@ -230,7 +229,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonNumberEntityDescription,
@@ -257,7 +256,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
await self._device.commands[command].send()
if command != "settings":
self._device.sync_command(command, "settings")
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
@@ -268,7 +267,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:
@@ -285,7 +284,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonConfigNumberEntityDescription,
@@ -300,7 +299,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
@property
def native_value(self) -> float | None:
if value := self._device.settings[self.entity_description.key].value:
if (value := self._device.settings[self.entity_description.key].value) != "":
return float(value)
return None
@@ -308,7 +307,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
setting = self._device.settings[self.entity_description.key]
if isinstance(setting, HonParameterRange):
setting.value = value
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@property
def available(self) -> bool:
@@ -324,4 +323,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()
+6 -7
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 callback, HomeAssistant
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
@@ -211,7 +210,7 @@ SELECTS["WD"] = unique_entities(SELECTS["WM"], SELECTS["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: HonSelectEntity | HonConfigSelectEntity
@@ -263,7 +262,7 @@ class HonConfigSelectEntity(HonEntity, SelectEntity):
async def async_select_option(self, option: str) -> None:
setting = self._device.settings[self.entity_description.key]
setting.value = self._option_to_number(option, setting.values)
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
@@ -271,7 +270,7 @@ class HonConfigSelectEntity(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()
@property
def available(self) -> bool:
@@ -317,7 +316,7 @@ class HonSelectEntity(HonEntity, SelectEntity):
await self._device.commands[command].send()
if command != "settings":
self._device.sync_command(command, "settings")
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@property
def available(self) -> bool:
@@ -334,4 +333,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()
+11 -7
View File
@@ -18,14 +18,12 @@ from homeassistant.const import (
UnitOfEnergy,
UnitOfVolume,
UnitOfMass,
UnitOfPower,
UnitOfTime,
UnitOfTemperature,
)
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
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
@@ -84,7 +82,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
name="Current Electricity Used",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
icon="mdi:lightning-bolt",
translation_key="energy_current",
),
@@ -514,6 +512,12 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
translation_key="mach_modes_ac",
option_list=const.AC_MACH_MODE,
),
HonSensorEntityDescription(
key="compressorFrequency",
name="Compressor Frequency",
icon="mdi:information",
device_class=SensorDeviceClass.FREQUENCY,
),
),
"REF": (
HonSensorEntityDescription(
@@ -809,7 +813,7 @@ SENSORS["WD"] = unique_entities(SENSORS["WM"], SENSORS["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: HonSensorEntity | HonConfigSensorEntity
@@ -847,7 +851,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):
@@ -875,4 +879,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()
+10 -11
View File
@@ -5,10 +5,9 @@ from typing import Any
from homeassistant.components.switch import SwitchEntityDescription, SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import callback, HomeAssistant
from homeassistant.helpers.entity import EntityCategory
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
@@ -403,7 +402,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
@@ -447,7 +446,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
setting.value = setting.max if isinstance(setting, HonParameterRange) else 1
self.async_write_ha_state()
await self._device.commands["settings"].send()
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
async def async_turn_off(self, **kwargs: Any) -> None:
setting = self._device.settings[f"settings.{self.entity_description.key}"]
@@ -456,7 +455,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
setting.value = setting.min if isinstance(setting, HonParameterRange) else 0
self.async_write_ha_state()
await self._device.commands["settings"].send()
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
@property
def available(self) -> bool:
@@ -476,7 +475,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):
@@ -489,14 +488,14 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
self._device.sync_command(self.entity_description.turn_on_key, "settings")
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
await self._device.commands[self.entity_description.turn_on_key].send()
self._device.attributes[self.entity_description.key] = True
self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None:
self._device.sync_command(self.entity_description.turn_off_key, "settings")
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
await self._device.commands[self.entity_description.turn_off_key].send()
self._device.attributes[self.entity_description.key] = False
self.async_write_ha_state()
@@ -541,7 +540,7 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
if type(setting) == HonParameter:
return
setting.value = setting.max if isinstance(setting, HonParameterRange) else "1"
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None:
@@ -549,11 +548,11 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
if type(setting) == HonParameter:
return
setting.value = setting.min if isinstance(setting, HonParameterRange) else "0"
self.async_write_ha_state()
self.coordinator.async_set_updated_data({})
self.async_write_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()
+1 -1
View File
@@ -1 +1 @@
pyhOn==0.17.3
pyhOn==0.17.5