New pyhOn version

This commit is contained in:
Andre Basche 2023-04-10 07:09:54 +02:00
parent e1a2af70e9
commit 7e9202ef38
9 changed files with 31 additions and 32 deletions

View file

@ -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"] = {}

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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"
}

View file

@ -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:

View file

@ -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

View file

@ -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:

View file

@ -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