diff --git a/custom_components/hon/__init__.py b/custom_components/hon/__init__.py index 8c3917b..c404243 100644 --- a/custom_components/hon/__init__.py +++ b/custom_components/hon/__init__.py @@ -1,7 +1,7 @@ import logging import voluptuous as vol -from pyhon import HonConnection +from pyhon import Hon from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EMAIL, CONF_PASSWORD @@ -28,8 +28,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): session = aiohttp_client.async_get_clientsession(hass) - hon = HonConnection(entry.data["email"], entry.data["password"], session) - await hon.setup() + hon = await Hon(entry.data["email"], entry.data["password"], session=session).create() hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.unique_id] = hon hass.data[DOMAIN]["coordinators"] = {} diff --git a/custom_components/hon/binary_sensor.py b/custom_components/hon/binary_sensor.py index a2f75c0..e6bccf8 100644 --- a/custom_components/hon/binary_sensor.py +++ b/custom_components/hon/binary_sensor.py @@ -1,7 +1,7 @@ import logging from dataclasses import dataclass -from pyhon import HonConnection +from pyhon import Hon from homeassistant.components.binary_sensor import BinarySensorEntityDescription, BinarySensorDeviceClass, \ BinarySensorEntity @@ -123,10 +123,10 @@ BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: diff --git a/custom_components/hon/button.py b/custom_components/hon/button.py index 4e24709..a2386b4 100644 --- a/custom_components/hon/button.py +++ b/custom_components/hon/button.py @@ -1,7 +1,7 @@ from homeassistant.components.button import ButtonEntityDescription, ButtonEntity from homeassistant.config_entries import ConfigEntry -from pyhon import HonConnection -from pyhon.device import HonDevice +from pyhon import Hon +from pyhon.appliance import HonAppliance from .const import DOMAIN from .hon import HonCoordinator, HonEntity @@ -23,10 +23,10 @@ BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: @@ -46,7 +46,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non class HonButtonEntity(HonEntity, ButtonEntity): - def __init__(self, hass, coordinator, entry, device: HonDevice, description) -> None: + def __init__(self, hass, coordinator, entry, device: HonAppliance, description) -> None: super().__init__(hass, entry, coordinator, device) self._coordinator = coordinator diff --git a/custom_components/hon/hon.py b/custom_components/hon/hon.py index 0b1578d..f68cf2b 100644 --- a/custom_components/hon/hon.py +++ b/custom_components/hon/hon.py @@ -1,7 +1,7 @@ import logging from datetime import timedelta -from pyhon.device import HonDevice +from pyhon.appliance import HonAppliance from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -15,7 +15,7 @@ _LOGGER = logging.getLogger(__name__) class HonEntity(CoordinatorEntity): _attr_has_entity_name = True - def __init__(self, hass, entry, coordinator, device: HonDevice) -> None: + def __init__(self, hass, entry, coordinator, device: HonAppliance) -> None: super().__init__(coordinator) self._hon = hass.data[DOMAIN][entry.unique_id] @@ -36,7 +36,7 @@ class HonEntity(CoordinatorEntity): class HonCoordinator(DataUpdateCoordinator): - def __init__(self, hass, device: HonDevice): + def __init__(self, hass, device: HonAppliance): """Initialize my coordinator.""" super().__init__(hass, _LOGGER, name=device.mac_address, update_interval=timedelta(seconds=30)) self._device = device diff --git a/custom_components/hon/manifest.json b/custom_components/hon/manifest.json index ea42851..25950a3 100644 --- a/custom_components/hon/manifest.json +++ b/custom_components/hon/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://github.com/Andre0512/hon/", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Andre0512/hon/issues", - "requirements": ["pyhOn==0.4.1"], - "version": "0.4.0" + "requirements": ["pyhOn==0.6.0"], + "version": "0.5.0-beta.1" } diff --git a/custom_components/hon/number.py b/custom_components/hon/number.py index 9ec2a0a..c2f588c 100644 --- a/custom_components/hon/number.py +++ b/custom_components/hon/number.py @@ -1,6 +1,6 @@ from __future__ import annotations -from pyhon import HonConnection +from pyhon import Hon from pyhon.parameter import HonParameterRange from homeassistant.components.number import ( @@ -111,10 +111,10 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: diff --git a/custom_components/hon/select.py b/custom_components/hon/select.py index 70c3468..ef8b010 100644 --- a/custom_components/hon/select.py +++ b/custom_components/hon/select.py @@ -2,8 +2,8 @@ from __future__ import annotations import logging -from pyhon import HonConnection -from pyhon.device import HonDevice +from pyhon import Hon +from pyhon.appliance import HonAppliance from pyhon.parameter import HonParameterFixed from homeassistant.components.select import SelectEntity, SelectEntityDescription @@ -79,10 +79,10 @@ SELECTS = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: @@ -101,7 +101,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non class HonSelectEntity(HonEntity, SelectEntity): - def __init__(self, hass, coordinator, entry, device: HonDevice, description) -> None: + def __init__(self, hass, coordinator, entry, device: HonAppliance, description) -> None: super().__init__(hass, entry, coordinator, device) self._coordinator = coordinator diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index aad957b..1bff6ff 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -1,6 +1,6 @@ import logging -from pyhon import HonConnection +from pyhon import Hon from homeassistant.components.sensor import ( SensorEntity, @@ -231,10 +231,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py index a4d3bf7..d37ceea 100644 --- a/custom_components/hon/switch.py +++ b/custom_components/hon/switch.py @@ -6,8 +6,8 @@ from typing import Any from homeassistant.components.switch import SwitchEntityDescription, SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import EntityCategory -from pyhon import HonConnection -from pyhon.device import HonDevice +from pyhon import Hon +from pyhon.appliance import HonAppliance from .const import DOMAIN from .hon import HonCoordinator, HonEntity @@ -93,10 +93,10 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = { async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None: - hon: HonConnection = hass.data[DOMAIN][entry.unique_id] + hon: Hon = hass.data[DOMAIN][entry.unique_id] coordinators = hass.data[DOMAIN]["coordinators"] appliances = [] - for device in hon.devices: + for device in hon.appliances: if device.mac_address in coordinators: coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address] else: @@ -119,7 +119,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non class HonSwitchEntity(HonEntity, SwitchEntity): entity_description: HonSwitchEntityDescription - def __init__(self, hass, coordinator, entry, device: HonDevice, description: HonSwitchEntityDescription) -> None: + def __init__(self, hass, coordinator, entry, device: HonAppliance, description: HonSwitchEntityDescription) -> None: super().__init__(hass, entry, coordinator, device) self._coordinator = coordinator self._device = device