mirror of
https://github.com/Andre0512/hon.git
synced 2026-07-04 16:22:43 +02:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e8a7b12dc | |||
| 3325bb27b9 | |||
| 6ffb7a4901 | |||
| 70eb6c0111 | |||
| 9bab35f8c4 | |||
| 39fc30c95e | |||
| 6906e751b1 | |||
| 6d2a6ce2e9 | |||
| 0e166f3c66 | |||
| 54dd406ec2 | |||
| a746584833 | |||
| 36aed2e6ea | |||
| 510c10bd9f | |||
| 09189ff0f8 | |||
| 0e26b4a0f7 | |||
| a6c2c3e992 | |||
| 8f1fc627e6 | |||
| c46171114f |
@@ -1,11 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
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.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.core import HomeAssistant
|
||||||
from pyhon import Hon
|
from pyhon import Hon
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS, MOBILE_ID, CONF_REFRESH_TOKEN
|
from .const import DOMAIN, PLATFORMS, MOBILE_ID, CONF_REFRESH_TOKEN
|
||||||
@@ -25,27 +27,31 @@ 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)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
if (config_dir := hass.config.config_dir) is None:
|
if (config_dir := hass.config.config_dir) is None:
|
||||||
raise ValueError("Missing Config Dir")
|
raise ValueError("Missing Config Dir")
|
||||||
kwargs = {
|
hon = await Hon(
|
||||||
"email": entry.data[CONF_EMAIL],
|
email=entry.data[CONF_EMAIL],
|
||||||
"password": entry.data[CONF_PASSWORD],
|
password=entry.data[CONF_PASSWORD],
|
||||||
"mobile_id": MOBILE_ID,
|
mobile_id=MOBILE_ID,
|
||||||
"session": session,
|
session=session,
|
||||||
"test_data_path": Path(config_dir),
|
test_data_path=Path(config_dir),
|
||||||
}
|
refresh_token=entry.data.get(CONF_REFRESH_TOKEN, ""),
|
||||||
if refresh_token := entry.data.get(CONF_REFRESH_TOKEN):
|
).create()
|
||||||
kwargs["refresh_token"] = refresh_token
|
|
||||||
hon = await Hon(**kwargs).create()
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
hass.data[DOMAIN][entry.unique_id] = hon
|
|
||||||
|
|
||||||
|
# Save the new refresh token
|
||||||
hass.config_entries.async_update_entry(
|
hass.config_entries.async_update_entry(
|
||||||
entry, data={**entry.data, CONF_REFRESH_TOKEN: hon.api.auth.refresh_token}
|
entry, data={**entry.data, CONF_REFRESH_TOKEN: hon.api.auth.refresh_token}
|
||||||
)
|
)
|
||||||
hass.data[DOMAIN]["coordinators"] = {}
|
|
||||||
|
coordinator: DataUpdateCoordinator[dict[str, Any]] = DataUpdateCoordinator(
|
||||||
|
hass, _LOGGER, name=DOMAIN
|
||||||
|
)
|
||||||
|
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}
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
for platform in PLATFORMS:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
@@ -54,8 +60,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
return True
|
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].api.auth.refresh_token
|
refresh_token = hass.data[DOMAIN][entry.unique_id]["hon"].api.auth.refresh_token
|
||||||
|
|
||||||
hass.config_entries.async_update_entry(
|
hass.config_entries.async_update_entry(
|
||||||
entry, data={**entry.data, CONF_REFRESH_TOKEN: refresh_token}
|
entry, data={**entry.data, CONF_REFRESH_TOKEN: refresh_token}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ 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 callback, HomeAssistant
|
||||||
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 .hon import HonEntity, unique_entities
|
from .entity import HonEntity
|
||||||
|
from .util import unique_entities
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -316,15 +316,14 @@ BINARY_SENSORS["WD"] = unique_entities(BINARY_SENSORS["WM"], BINARY_SENSORS["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 = []
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in BINARY_SENSORS.get(device.appliance_type, []):
|
for description in BINARY_SENSORS.get(device.appliance_type, []):
|
||||||
if device.get(description.key) is None:
|
if device.get(description.key) is None:
|
||||||
continue
|
continue
|
||||||
entity = HonBinarySensorEntity(hass, entry, device, description)
|
entity = HonBinarySensorEntity(hass, entry, device, description)
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@@ -346,4 +345,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()
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ from homeassistant.components.button import ButtonEntityDescription, ButtonEntit
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
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.appliance import HonAppliance
|
from pyhon.appliance import HonAppliance
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity
|
from .entity import HonEntity
|
||||||
from .typedefs import HonButtonType
|
from .typedefs import HonButtonType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -56,19 +56,17 @@ BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = {
|
|||||||
|
|
||||||
|
|
||||||
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: list[HonButtonType] = []
|
entities: list[HonButtonType] = []
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in BUTTONS.get(device.appliance_type, []):
|
for description in BUTTONS.get(device.appliance_type, []):
|
||||||
if not device.commands.get(description.key):
|
if not device.commands.get(description.key):
|
||||||
continue
|
continue
|
||||||
entity = HonButtonEntity(hass, entry, device, description)
|
entity = HonButtonEntity(hass, entry, device, description)
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
entities.append(HonDeviceInfo(hass, entry, device))
|
entities.append(HonDeviceInfo(hass, entry, device))
|
||||||
entities.append(HonDataArchive(hass, entry, device))
|
entities.append(HonDataArchive(hass, entry, device))
|
||||||
await entities[-1].coordinator.async_config_entry_first_refresh()
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,13 +82,13 @@ class HonButtonEntity(HonEntity, ButtonEntity):
|
|||||||
return (
|
return (
|
||||||
super().available
|
super().available
|
||||||
and int(self._device.get("remoteCtrValid", "1")) == 1
|
and int(self._device.get("remoteCtrValid", "1")) == 1
|
||||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
and self._device.connection
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HonDeviceInfo(HonEntity, ButtonEntity):
|
class HonDeviceInfo(HonEntity, ButtonEntity):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
|
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(hass, entry, device)
|
super().__init__(hass, entry, device)
|
||||||
|
|
||||||
@@ -98,24 +96,19 @@ class HonDeviceInfo(HonEntity, ButtonEntity):
|
|||||||
self._attr_icon = "mdi:information"
|
self._attr_icon = "mdi:information"
|
||||||
self._attr_name = "Show Device Info"
|
self._attr_name = "Show Device Info"
|
||||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
if "beta" not in self.coordinator.info.hon_version:
|
self._attr_entity_registry_enabled_default = False
|
||||||
self._attr_entity_registry_enabled_default = False
|
|
||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
versions = "versions:\n"
|
|
||||||
versions += f" hon: {self.coordinator.info.hon_version}\n"
|
|
||||||
versions += f" pyhOn: {self.coordinator.info.pyhon_version}\n"
|
|
||||||
info = f"{self._device.diagnose}{versions}"
|
|
||||||
title = f"{self._device.nick_name} Device Info"
|
title = f"{self._device.nick_name} Device Info"
|
||||||
persistent_notification.create(
|
persistent_notification.create(
|
||||||
self._hass, f"````\n```\n{info}\n```\n````", title
|
self._hass, f"````\n```\n{self._device.diagnose}\n```\n````", title
|
||||||
)
|
)
|
||||||
_LOGGER.info(info.replace(" ", "\u200B "))
|
_LOGGER.info(self._device.diagnose.replace(" ", "\u200B "))
|
||||||
|
|
||||||
|
|
||||||
class HonDataArchive(HonEntity, ButtonEntity):
|
class HonDataArchive(HonEntity, ButtonEntity):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistantType, entry: ConfigEntry, device: HonAppliance
|
self, hass: HomeAssistant, entry: ConfigEntry, device: HonAppliance
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(hass, entry, device)
|
super().__init__(hass, entry, device)
|
||||||
|
|
||||||
@@ -123,8 +116,7 @@ class HonDataArchive(HonEntity, ButtonEntity):
|
|||||||
self._attr_icon = "mdi:archive-arrow-down"
|
self._attr_icon = "mdi:archive-arrow-down"
|
||||||
self._attr_name = "Create Data Archive"
|
self._attr_name = "Create Data Archive"
|
||||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
if "beta" not in self.coordinator.info.hon_version:
|
self._attr_entity_registry_enabled_default = False
|
||||||
self._attr_entity_registry_enabled_default = False
|
|
||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
if (config_dir := self._hass.config.config_dir) is None:
|
if (config_dir := self._hass.config.config_dir) is None:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -19,14 +20,13 @@ from homeassistant.const import (
|
|||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback, HomeAssistant
|
||||||
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
|
||||||
|
|
||||||
from .const import HON_HVAC_MODE, HON_FAN, DOMAIN, HON_HVAC_PROGRAM
|
from .const import HON_HVAC_MODE, HON_FAN, DOMAIN, HON_HVAC_PROGRAM
|
||||||
from .hon import HonEntity
|
from .entity import HonEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -104,11 +104,11 @@ CLIMATES: dict[
|
|||||||
|
|
||||||
|
|
||||||
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: HonClimateEntity | HonACClimateEntity
|
entity: HonClimateEntity | HonACClimateEntity
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in CLIMATES.get(device.appliance_type, []):
|
for description in CLIMATES.get(device.appliance_type, []):
|
||||||
if isinstance(description, HonACClimateEntityDescription):
|
if isinstance(description, HonACClimateEntityDescription):
|
||||||
if description.key not in list(device.commands):
|
if description.key not in list(device.commands):
|
||||||
@@ -120,17 +120,17 @@ async def async_setup_entry(
|
|||||||
entity = HonClimateEntity(hass, entry, device, description)
|
entity = HonClimateEntity(hass, entry, device, description)
|
||||||
else:
|
else:
|
||||||
continue # type: ignore[unreachable]
|
continue # type: ignore[unreachable]
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class HonACClimateEntity(HonEntity, ClimateEntity):
|
class HonACClimateEntity(HonEntity, ClimateEntity):
|
||||||
entity_description: HonACClimateEntityDescription
|
entity_description: HonACClimateEntityDescription
|
||||||
|
_enable_turn_on_off_backwards_compatibility = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: HonACClimateEntityDescription,
|
description: HonACClimateEntityDescription,
|
||||||
@@ -212,6 +212,14 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||||||
await self._device.commands["settings"].send()
|
await self._device.commands["settings"].send()
|
||||||
self.async_write_ha_state()
|
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
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
"""Return the current Preset for this channel."""
|
"""Return the current Preset for this channel."""
|
||||||
@@ -224,7 +232,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||||||
self._device.sync_command("startProgram", "settings")
|
self._device.sync_command("startProgram", "settings")
|
||||||
self._set_temperature_bound()
|
self._set_temperature_bound()
|
||||||
self._handle_coordinator_update(update=False)
|
self._handle_coordinator_update(update=False)
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
self._attr_preset_mode = preset_mode
|
self._attr_preset_mode = preset_mode
|
||||||
await self._device.commands["startProgram"].send()
|
await self._device.commands["startProgram"].send()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
@@ -282,15 +290,16 @@ class HonACClimateEntity(HonEntity, ClimateEntity):
|
|||||||
@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()
|
||||||
|
|
||||||
|
|
||||||
class HonClimateEntity(HonEntity, ClimateEntity):
|
class HonClimateEntity(HonEntity, ClimateEntity):
|
||||||
entity_description: HonClimateEntityDescription
|
entity_description: HonClimateEntityDescription
|
||||||
|
_enable_turn_on_off_backwards_compatibility = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: HonClimateEntityDescription,
|
description: HonClimateEntityDescription,
|
||||||
@@ -364,6 +373,14 @@ class HonClimateEntity(HonEntity, ClimateEntity):
|
|||||||
self._attr_hvac_mode = hvac_mode
|
self._attr_hvac_mode = hvac_mode
|
||||||
self.async_write_ha_state()
|
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
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
"""Return the current Preset for this channel."""
|
"""Return the current Preset for this channel."""
|
||||||
@@ -391,7 +408,7 @@ class HonClimateEntity(HonEntity, ClimateEntity):
|
|||||||
self._device.sync_command(command, "settings")
|
self._device.sync_command(command, "settings")
|
||||||
self._set_temperature_bound()
|
self._set_temperature_bound()
|
||||||
self._attr_preset_mode = preset_mode
|
self._attr_preset_mode = preset_mode
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
await self._device.commands[command].send()
|
await self._device.commands[command].send()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@@ -406,4 +423,4 @@ class HonClimateEntity(HonEntity, ClimateEntity):
|
|||||||
@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()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from homeassistant.components.climate import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
DOMAIN: str = "hon"
|
DOMAIN: str = "hon"
|
||||||
UPDATE_INTERVAL: int = 60
|
|
||||||
MOBILE_ID: str = "homassistant"
|
MOBILE_ID: str = "homassistant"
|
||||||
CONF_REFRESH_TOKEN = "refresh_token"
|
CONF_REFRESH_TOKEN = "refresh_token"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
from typing import Optional, Any
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import callback, HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
CoordinatorEntity,
|
||||||
|
)
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
from pyhon.appliance import HonAppliance
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .typedefs import HonEntityDescription
|
||||||
|
|
||||||
|
|
||||||
|
class HonEntity(CoordinatorEntity[DataUpdateCoordinator[dict[str, Any]]]):
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
device: HonAppliance,
|
||||||
|
description: Optional[HonEntityDescription] = None,
|
||||||
|
) -> None:
|
||||||
|
self.coordinator = hass.data[DOMAIN][entry.unique_id]["coordinator"]
|
||||||
|
super().__init__(self.coordinator)
|
||||||
|
self._hon = hass.data[DOMAIN][entry.unique_id]["hon"]
|
||||||
|
self._hass = hass
|
||||||
|
self._device: HonAppliance = device
|
||||||
|
|
||||||
|
if description is not None:
|
||||||
|
self.entity_description = description
|
||||||
|
self._attr_unique_id = f"{self._device.unique_id}{description.key}"
|
||||||
|
else:
|
||||||
|
self._attr_unique_id = self._device.unique_id
|
||||||
|
self._handle_coordinator_update(update=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
return DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self._device.unique_id)},
|
||||||
|
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.schedule_update_ha_state()
|
||||||
@@ -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 callback, HomeAssistant
|
||||||
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,
|
||||||
@@ -19,7 +18,7 @@ from pyhon.appliance import HonAppliance
|
|||||||
from pyhon.parameter.range import HonParameterRange
|
from pyhon.parameter.range import HonParameterRange
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity
|
from .entity import HonEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -36,10 +35,10 @@ FANS: dict[str, tuple[FanEntityDescription, ...]] = {
|
|||||||
|
|
||||||
|
|
||||||
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 = []
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in FANS.get(device.appliance_type, []):
|
for description in FANS.get(device.appliance_type, []):
|
||||||
if (
|
if (
|
||||||
description.key not in device.available_settings
|
description.key not in device.available_settings
|
||||||
@@ -47,7 +46,6 @@ async def async_setup_entry(
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
entity = HonFanEntity(hass, entry, device, description)
|
entity = HonFanEntity(hass, entry, device, description)
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ class HonFanEntity(HonEntity, FanEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: FanEntityDescription,
|
description: FanEntityDescription,
|
||||||
@@ -126,7 +124,7 @@ class HonFanEntity(HonEntity, FanEntity):
|
|||||||
)
|
)
|
||||||
self._attr_percentage = self.percentage
|
self._attr_percentage = self.percentage
|
||||||
if update:
|
if update:
|
||||||
self.async_write_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
import json
|
|
||||||
import logging
|
|
||||||
from contextlib import suppress
|
|
||||||
from datetime import timedelta
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Optional, Any
|
|
||||||
|
|
||||||
import pkg_resources # type: ignore[import, unused-ignore]
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
||||||
from pyhon.appliance import HonAppliance
|
|
||||||
|
|
||||||
from .const import DOMAIN, UPDATE_INTERVAL
|
|
||||||
from .typedefs import HonEntityDescription, HonOptionEntityDescription, T
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class HonInfo:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._manifest: dict[str, Any] = self._get_manifest()
|
|
||||||
self._hon_version: str = self._manifest.get("version", "")
|
|
||||||
self._pyhon_version: str = pkg_resources.get_distribution("pyhon").version
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_manifest() -> dict[str, Any]:
|
|
||||||
manifest = Path(__file__).parent / "manifest.json"
|
|
||||||
with open(manifest, "r", encoding="utf-8") as file:
|
|
||||||
result: dict[str, Any] = json.loads(file.read())
|
|
||||||
return result
|
|
||||||
|
|
||||||
@property
|
|
||||||
def manifest(self) -> dict[str, Any]:
|
|
||||||
return self._manifest
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hon_version(self) -> str:
|
|
||||||
return self._hon_version
|
|
||||||
|
|
||||||
@property
|
|
||||||
def pyhon_version(self) -> str:
|
|
||||||
return self._pyhon_version
|
|
||||||
|
|
||||||
|
|
||||||
class HonCoordinator(DataUpdateCoordinator[None]):
|
|
||||||
def __init__(self, hass: HomeAssistantType, device: HonAppliance):
|
|
||||||
"""Initialize my coordinator."""
|
|
||||||
super().__init__(
|
|
||||||
hass,
|
|
||||||
_LOGGER,
|
|
||||||
name=device.unique_id,
|
|
||||||
update_interval=timedelta(seconds=UPDATE_INTERVAL),
|
|
||||||
)
|
|
||||||
self._device = device
|
|
||||||
self._info = HonInfo()
|
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
|
||||||
return await self._device.update()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def info(self) -> HonInfo:
|
|
||||||
return self._info
|
|
||||||
|
|
||||||
|
|
||||||
class HonEntity(CoordinatorEntity[HonCoordinator]):
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistantType,
|
|
||||||
entry: ConfigEntry,
|
|
||||||
device: HonAppliance,
|
|
||||||
description: Optional[HonEntityDescription] = None,
|
|
||||||
) -> None:
|
|
||||||
coordinator = get_coordinator(hass, device)
|
|
||||||
super().__init__(coordinator)
|
|
||||||
|
|
||||||
self._hon = hass.data[DOMAIN][entry.unique_id]
|
|
||||||
self._hass = hass
|
|
||||||
self._coordinator = coordinator
|
|
||||||
self._device: HonAppliance = device
|
|
||||||
|
|
||||||
if description is not None:
|
|
||||||
self.entity_description = description
|
|
||||||
self._attr_unique_id = f"{self._device.unique_id}{description.key}"
|
|
||||||
else:
|
|
||||||
self._attr_unique_id = self._device.unique_id
|
|
||||||
self._handle_coordinator_update(update=False)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._device.unique_id)},
|
|
||||||
manufacturer=self._device.get("brand", ""),
|
|
||||||
name=self._device.nick_name,
|
|
||||||
model=self._device.model_name,
|
|
||||||
sw_version=self._device.get("fwVersion", ""),
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def _handle_coordinator_update(self, update: bool = True) -> None:
|
|
||||||
if update:
|
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
|
|
||||||
def unique_entities(
|
|
||||||
base_entities: tuple[T, ...],
|
|
||||||
new_entities: tuple[T, ...],
|
|
||||||
) -> tuple[T, ...]:
|
|
||||||
result = list(base_entities)
|
|
||||||
existing_entities = [entity.key for entity in base_entities]
|
|
||||||
entity: HonEntityDescription
|
|
||||||
for entity in new_entities:
|
|
||||||
if entity.key not in existing_entities:
|
|
||||||
result.append(entity)
|
|
||||||
return tuple(result)
|
|
||||||
|
|
||||||
|
|
||||||
def get_coordinator(hass: HomeAssistantType, appliance: HonAppliance) -> HonCoordinator:
|
|
||||||
coordinators = hass.data[DOMAIN]["coordinators"]
|
|
||||||
if appliance.unique_id in coordinators:
|
|
||||||
coordinator: HonCoordinator = hass.data[DOMAIN]["coordinators"][
|
|
||||||
appliance.unique_id
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
coordinator = HonCoordinator(hass, appliance)
|
|
||||||
hass.data[DOMAIN]["coordinators"][appliance.unique_id] = coordinator
|
|
||||||
return coordinator
|
|
||||||
|
|
||||||
|
|
||||||
def get_readable(
|
|
||||||
description: HonOptionEntityDescription, value: float | str
|
|
||||||
) -> float | str:
|
|
||||||
if description.option_list is not None:
|
|
||||||
with suppress(ValueError):
|
|
||||||
return description.option_list.get(int(value), value)
|
|
||||||
return value
|
|
||||||
@@ -8,14 +8,13 @@ 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 callback, HomeAssistant
|
||||||
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
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity
|
from .entity import HonEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -53,10 +52,10 @@ LIGHTS: dict[str, tuple[LightEntityDescription, ...]] = {
|
|||||||
|
|
||||||
|
|
||||||
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 = []
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in LIGHTS.get(device.appliance_type, []):
|
for description in LIGHTS.get(device.appliance_type, []):
|
||||||
if (
|
if (
|
||||||
description.key not in device.available_settings
|
description.key not in device.available_settings
|
||||||
@@ -64,7 +63,6 @@ async def async_setup_entry(
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
entity = HonLightEntity(hass, entry, device, description)
|
entity = HonLightEntity(hass, entry, device, description)
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@@ -74,7 +72,7 @@ class HonLightEntity(HonEntity, LightEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: LightEntityDescription,
|
description: LightEntityDescription,
|
||||||
@@ -137,7 +135,7 @@ class HonLightEntity(HonEntity, LightEntity):
|
|||||||
self._attr_is_on = self.is_on
|
self._attr_is_on = self.is_on
|
||||||
self._attr_brightness = self.brightness
|
self._attr_brightness = self.brightness
|
||||||
if update:
|
if update:
|
||||||
self.async_write_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ 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 callback, HomeAssistant
|
||||||
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
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity
|
from .entity import HonEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -26,10 +25,10 @@ LOCKS: dict[str, tuple[LockEntityDescription, ...]] = {
|
|||||||
|
|
||||||
|
|
||||||
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 = []
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in LOCKS.get(device.appliance_type, []):
|
for description in LOCKS.get(device.appliance_type, []):
|
||||||
if (
|
if (
|
||||||
f"settings.{description.key}" not in device.available_settings
|
f"settings.{description.key}" not in device.available_settings
|
||||||
@@ -37,7 +36,6 @@ async def async_setup_entry(
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
entity = HonLockEntity(hass, entry, device, description)
|
entity = HonLockEntity(hass, entry, device, description)
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@@ -59,7 +57,7 @@ class HonLockEntity(HonEntity, LockEntity):
|
|||||||
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()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
async def async_unlock(self, **kwargs: Any) -> None:
|
async def async_unlock(self, **kwargs: Any) -> None:
|
||||||
"""Unlock method."""
|
"""Unlock method."""
|
||||||
@@ -69,7 +67,7 @@ class HonLockEntity(HonEntity, LockEntity):
|
|||||||
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()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -77,7 +75,7 @@ class HonLockEntity(HonEntity, LockEntity):
|
|||||||
return (
|
return (
|
||||||
super().available
|
super().available
|
||||||
and int(self._device.get("remoteCtrValid", 1)) == 1
|
and int(self._device.get("remoteCtrValid", 1)) == 1
|
||||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
and self._device.connection
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
],
|
],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://github.com/Andre0512/hon/",
|
"documentation": "https://github.com/Andre0512/hon/",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_push",
|
||||||
"issue_tracker": "https://github.com/Andre0512/hon/issues",
|
"issue_tracker": "https://github.com/Andre0512/hon/issues",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyhOn==0.16.1"
|
"pyhOn==0.17.5"
|
||||||
],
|
],
|
||||||
"version": "0.14.0-beta.1"
|
"version": "0.14.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ 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 callback, HomeAssistant
|
||||||
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
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity, unique_entities
|
from .entity import HonEntity
|
||||||
|
from .util import unique_entities
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@@ -206,11 +206,11 @@ NUMBERS["WD"] = unique_entities(NUMBERS["WM"], NUMBERS["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: HonNumberEntity | HonConfigNumberEntity
|
entity: HonNumberEntity | HonConfigNumberEntity
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in NUMBERS.get(device.appliance_type, []):
|
for description in NUMBERS.get(device.appliance_type, []):
|
||||||
if description.key not in device.available_settings:
|
if description.key not in device.available_settings:
|
||||||
continue
|
continue
|
||||||
@@ -220,7 +220,6 @@ async def async_setup_entry(
|
|||||||
entity = HonConfigNumberEntity(hass, entry, device, description)
|
entity = HonConfigNumberEntity(hass, entry, device, description)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@@ -230,7 +229,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: HonNumberEntityDescription,
|
description: HonNumberEntityDescription,
|
||||||
@@ -257,7 +256,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
|
|||||||
await self._device.commands[command].send()
|
await self._device.commands[command].send()
|
||||||
if command != "settings":
|
if command != "settings":
|
||||||
self._device.sync_command(command, "settings")
|
self._device.sync_command(command, "settings")
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self, update: bool = True) -> None:
|
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_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:
|
||||||
@@ -276,7 +275,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
|
|||||||
return (
|
return (
|
||||||
super().available
|
super().available
|
||||||
and int(self._device.get("remoteCtrValid", 1)) == 1
|
and int(self._device.get("remoteCtrValid", 1)) == 1
|
||||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
and self._device.connection
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +284,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
device: HonAppliance,
|
device: HonAppliance,
|
||||||
description: HonConfigNumberEntityDescription,
|
description: HonConfigNumberEntityDescription,
|
||||||
@@ -300,7 +299,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float | None:
|
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 float(value)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -308,7 +307,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):
|
|||||||
setting = self._device.settings[self.entity_description.key]
|
setting = self._device.settings[self.entity_description.key]
|
||||||
if isinstance(setting, HonParameterRange):
|
if isinstance(setting, HonParameterRange):
|
||||||
setting.value = value
|
setting.value = value
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -324,4 +323,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()
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ 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 callback, HomeAssistant
|
||||||
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
|
||||||
from .hon import HonEntity, unique_entities, get_readable
|
from .entity import HonEntity
|
||||||
|
from .util import unique_entities, get_readable
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -210,11 +210,11 @@ SELECTS["WD"] = unique_entities(SELECTS["WM"], SELECTS["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: HonSelectEntity | HonConfigSelectEntity
|
entity: HonSelectEntity | HonConfigSelectEntity
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in SELECTS.get(device.appliance_type, []):
|
for description in SELECTS.get(device.appliance_type, []):
|
||||||
if description.key not in device.available_settings:
|
if description.key not in device.available_settings:
|
||||||
continue
|
continue
|
||||||
@@ -224,7 +224,6 @@ async def async_setup_entry(
|
|||||||
entity = HonConfigSelectEntity(hass, entry, device, description)
|
entity = HonConfigSelectEntity(hass, entry, device, description)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@@ -263,7 +262,7 @@ class HonConfigSelectEntity(HonEntity, SelectEntity):
|
|||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
setting = self._device.settings[self.entity_description.key]
|
setting = self._device.settings[self.entity_description.key]
|
||||||
setting.value = self._option_to_number(option, setting.values)
|
setting.value = self._option_to_number(option, setting.values)
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self, update: bool = True) -> None:
|
def _handle_coordinator_update(self, update: bool = True) -> None:
|
||||||
@@ -271,7 +270,7 @@ class HonConfigSelectEntity(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()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -317,7 +316,7 @@ class HonSelectEntity(HonEntity, SelectEntity):
|
|||||||
await self._device.commands[command].send()
|
await self._device.commands[command].send()
|
||||||
if command != "settings":
|
if command != "settings":
|
||||||
self._device.sync_command(command, "settings")
|
self._device.sync_command(command, "settings")
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -325,7 +324,7 @@ class HonSelectEntity(HonEntity, SelectEntity):
|
|||||||
return (
|
return (
|
||||||
super().available
|
super().available
|
||||||
and int(self._device.get("remoteCtrValid", 1)) == 1
|
and int(self._device.get("remoteCtrValid", 1)) == 1
|
||||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
and self._device.connection
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@@ -334,4 +333,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()
|
||||||
|
|||||||
@@ -18,18 +18,17 @@ from homeassistant.const import (
|
|||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfVolume,
|
UnitOfVolume,
|
||||||
UnitOfMass,
|
UnitOfMass,
|
||||||
UnitOfPower,
|
|
||||||
UnitOfTime,
|
UnitOfTime,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback, HomeAssistant
|
||||||
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
|
||||||
from .hon import HonEntity, unique_entities, get_readable
|
from .entity import HonEntity
|
||||||
|
from .util import unique_entities, get_readable
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||||||
name="Current Electricity Used",
|
name="Current Electricity Used",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
icon="mdi:lightning-bolt",
|
icon="mdi:lightning-bolt",
|
||||||
translation_key="energy_current",
|
translation_key="energy_current",
|
||||||
),
|
),
|
||||||
@@ -513,6 +512,12 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||||||
translation_key="mach_modes_ac",
|
translation_key="mach_modes_ac",
|
||||||
option_list=const.AC_MACH_MODE,
|
option_list=const.AC_MACH_MODE,
|
||||||
),
|
),
|
||||||
|
HonSensorEntityDescription(
|
||||||
|
key="compressorFrequency",
|
||||||
|
name="Compressor Frequency",
|
||||||
|
icon="mdi:information",
|
||||||
|
device_class=SensorDeviceClass.FREQUENCY,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
"REF": (
|
"REF": (
|
||||||
HonSensorEntityDescription(
|
HonSensorEntityDescription(
|
||||||
@@ -808,11 +813,11 @@ SENSORS["WD"] = unique_entities(SENSORS["WM"], SENSORS["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: HonSensorEntity | HonConfigSensorEntity
|
entity: HonSensorEntity | HonConfigSensorEntity
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in SENSORS.get(device.appliance_type, []):
|
for description in SENSORS.get(device.appliance_type, []):
|
||||||
if isinstance(description, HonSensorEntityDescription):
|
if isinstance(description, HonSensorEntityDescription):
|
||||||
if device.get(description.key) is None:
|
if device.get(description.key) is None:
|
||||||
@@ -824,7 +829,6 @@ async def async_setup_entry(
|
|||||||
entity = HonConfigSensorEntity(hass, entry, device, description)
|
entity = HonConfigSensorEntity(hass, entry, device, description)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@@ -847,7 +851,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):
|
||||||
@@ -875,4 +879,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()
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntityDescription, SwitchEntity
|
from homeassistant.components.switch import SwitchEntityDescription, SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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 import EntityCategory
|
||||||
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
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonEntity, unique_entities
|
from .entity import HonEntity
|
||||||
|
from .util import unique_entities
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -402,11 +402,11 @@ 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
|
||||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||||
for description in SWITCHES.get(device.appliance_type, []):
|
for description in SWITCHES.get(device.appliance_type, []):
|
||||||
if isinstance(description, HonConfigSwitchEntityDescription):
|
if isinstance(description, HonConfigSwitchEntityDescription):
|
||||||
if description.key not in device.available_settings:
|
if description.key not in device.available_settings:
|
||||||
@@ -426,7 +426,6 @@ async def async_setup_entry(
|
|||||||
entity = HonSwitchEntity(hass, entry, device, description)
|
entity = HonSwitchEntity(hass, entry, device, description)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
await entity.coordinator.async_config_entry_first_refresh()
|
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@@ -447,7 +446,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
|||||||
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()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
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
|
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()
|
self.coordinator.async_set_updated_data({})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
@@ -476,7 +475,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):
|
||||||
@@ -489,14 +488,14 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
self._device.sync_command(self.entity_description.turn_on_key, "settings")
|
self._device.sync_command(self.entity_description.turn_on_key, "settings")
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
await self._device.commands[self.entity_description.turn_on_key].send()
|
await self._device.commands[self.entity_description.turn_on_key].send()
|
||||||
self._device.attributes[self.entity_description.key] = True
|
self._device.attributes[self.entity_description.key] = True
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
self._device.sync_command(self.entity_description.turn_off_key, "settings")
|
self._device.sync_command(self.entity_description.turn_off_key, "settings")
|
||||||
await self.coordinator.async_refresh()
|
self.coordinator.async_set_updated_data({})
|
||||||
await self._device.commands[self.entity_description.turn_off_key].send()
|
await self._device.commands[self.entity_description.turn_off_key].send()
|
||||||
self._device.attributes[self.entity_description.key] = False
|
self._device.attributes[self.entity_description.key] = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
@@ -507,7 +506,7 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
|
|||||||
return (
|
return (
|
||||||
super().available
|
super().available
|
||||||
and int(self._device.get("remoteCtrValid", 1)) == 1
|
and int(self._device.get("remoteCtrValid", 1)) == 1
|
||||||
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
|
and self._device.connection
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -541,19 +540,19 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
|
|||||||
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.coordinator.async_set_updated_data({})
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
await self.coordinator.async_refresh()
|
|
||||||
|
|
||||||
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]
|
||||||
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.coordinator.async_set_updated_data({})
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
await self.coordinator.async_refresh()
|
|
||||||
|
|
||||||
@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()
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import logging
|
||||||
|
from contextlib import suppress
|
||||||
|
|
||||||
|
from .typedefs import HonEntityDescription, HonOptionEntityDescription, T
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def unique_entities(
|
||||||
|
base_entities: tuple[T, ...],
|
||||||
|
new_entities: tuple[T, ...],
|
||||||
|
) -> tuple[T, ...]:
|
||||||
|
result = list(base_entities)
|
||||||
|
existing_entities = [entity.key for entity in base_entities]
|
||||||
|
entity: HonEntityDescription
|
||||||
|
for entity in new_entities:
|
||||||
|
if entity.key not in existing_entities:
|
||||||
|
result.append(entity)
|
||||||
|
return tuple(result)
|
||||||
|
|
||||||
|
|
||||||
|
def get_readable(
|
||||||
|
description: HonOptionEntityDescription, value: float | str
|
||||||
|
) -> float | str:
|
||||||
|
if description.option_list is not None:
|
||||||
|
with suppress(ValueError):
|
||||||
|
return description.option_list.get(int(value), value)
|
||||||
|
return value
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
pyhOn==0.16.0
|
pyhOn==0.17.5
|
||||||
|
|||||||
Reference in New Issue
Block a user