Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions custom_components/hon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from pyhon import Hon

Expand All @@ -27,7 +27,7 @@
)


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")
Expand All @@ -53,14 +53,12 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.unique_id] = {"hon": hon, "coordinator": coordinator}

for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

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(
Expand Down
16 changes: 13 additions & 3 deletions custom_components/hon/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .entity import HonEntity
Expand Down Expand Up @@ -285,6 +285,16 @@ class HonBinarySensorEntityDescription(BinarySensorEntityDescription):
translation_key="on",
),
),
"WH": (
HonBinarySensorEntityDescription(
key="onOffStatus",
name="Power State",
icon="mdi:power-standby",
device_class=BinarySensorDeviceClass.POWER,
on_value=1,
translation_key="power-state",
),
),
"FRE": (
HonBinarySensorEntityDescription(
key="quickModeZ1",
Expand Down Expand Up @@ -317,7 +327,7 @@ class HonBinarySensorEntityDescription(BinarySensorEntityDescription):


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:
Expand Down Expand Up @@ -346,4 +356,4 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
== self.entity_description.on_value
)
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
8 changes: 4 additions & 4 deletions custom_components/hon/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down Expand Up @@ -56,7 +56,7 @@


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:
Expand Down Expand Up @@ -88,7 +88,7 @@ def available(self) -> bool:

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)

Expand All @@ -108,7 +108,7 @@ async def async_press(self) -> None:

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)

Expand Down
9 changes: 4 additions & 5 deletions custom_components/hon/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
ATTR_TEMPERATURE,
UnitOfTemperature,
)
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand Down Expand Up @@ -104,7 +103,7 @@ class HonClimateEntityDescription(ClimateEntityDescription):


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
Expand All @@ -130,7 +129,7 @@ class HonACClimateEntity(HonEntity, ClimateEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonACClimateEntityDescription,
Expand Down Expand Up @@ -299,7 +298,7 @@ class HonClimateEntity(HonEntity, ClimateEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonClimateEntityDescription,
Expand Down
6 changes: 6 additions & 0 deletions custom_components/hon/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,9 @@
7: "position_5",
8: "swing",
}

WH_MACH_MODE: dict[int, str] = {
1: "eco",
2: "max",
3: "bps",
}
7 changes: 3 additions & 4 deletions custom_components/hon/entity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional, Any

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
)
Expand All @@ -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,
Expand Down Expand Up @@ -53,4 +52,4 @@ def device_info(self) -> DeviceInfo:
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
if update:
self.async_write_ha_state()
self.schedule_update_ha_state()
7 changes: 3 additions & 4 deletions custom_components/hon/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
FanEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.percentage import (
percentage_to_ranged_value,
ranged_value_to_percentage,
Expand All @@ -36,7 +35,7 @@


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:
Expand All @@ -56,7 +55,7 @@ class HonFanEntity(HonEntity, FanEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: FanEntityDescription,
Expand Down
7 changes: 3 additions & 4 deletions custom_components/hon/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
ATTR_BRIGHTNESS,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand Down Expand Up @@ -53,7 +52,7 @@


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:
Expand All @@ -73,7 +72,7 @@ class HonLightEntity(HonEntity, LightEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: LightEntityDescription,
Expand Down
5 changes: 2 additions & 3 deletions custom_components/hon/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange

Expand All @@ -26,7 +25,7 @@


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:
Expand Down
35 changes: 25 additions & 10 deletions custom_components/hon/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from homeassistant.components.number import (
NumberEntity,
NumberEntityDescription,
NumberDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTime, UnitOfTemperature
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
from pyhon.appliance import HonAppliance
from pyhon.parameter.range import HonParameterRange

Expand All @@ -27,7 +27,7 @@ class HonConfigNumberEntityDescription(NumberEntityDescription):

@dataclass(frozen=True)
class HonNumberEntityDescription(NumberEntityDescription):
pass
send_key_only: bool = False


NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
Expand Down Expand Up @@ -201,13 +201,24 @@ class HonNumberEntityDescription(NumberEntityDescription):
translation_key="pollen_level",
),
),
"WH": (
HonNumberEntityDescription(
key="settings.tempSel",
name="Target Temperature",
icon="mdi:thermometer",
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
translation_key="target_temperature",
send_key_only=True,
),
),
}

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
Expand All @@ -230,7 +241,7 @@ class HonNumberEntity(HonEntity, NumberEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonNumberEntityDescription,
Expand All @@ -253,8 +264,12 @@ async def async_set_native_value(self, value: float) -> None:
setting = self._device.settings[self.entity_description.key]
if isinstance(setting, HonParameterRange):
setting.value = value
command = self.entity_description.key.split(".")[0]
await self._device.commands[command].send()
key_parts = self.entity_description.key.split(".")
command = key_parts[0]
if self.entity_description.send_key_only:
await self._device.commands[command].send_specific([key_parts[1]])
else:
await self._device.commands[command].send()
if command != "settings":
self._device.sync_command(command, "settings")
self.coordinator.async_set_updated_data({})
Expand All @@ -268,7 +283,7 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
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:
Expand All @@ -285,7 +300,7 @@ class HonConfigNumberEntity(HonEntity, NumberEntity):

def __init__(
self,
hass: HomeAssistantType,
hass: HomeAssistant,
entry: ConfigEntry,
device: HonAppliance,
description: HonConfigNumberEntityDescription,
Expand Down Expand Up @@ -324,4 +339,4 @@ def _handle_coordinator_update(self, update: bool = True) -> None:
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()
Loading