mirror of https://github.com/Andre0512/hon.git
New pyhOn version
This commit is contained in:
parent
e1a2af70e9
commit
7e9202ef38
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
|
|
||||||
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
|
||||||
|
@ -28,8 +28,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
hon = HonConnection(entry.data["email"], entry.data["password"], session)
|
hon = await Hon(entry.data["email"], entry.data["password"], session=session).create()
|
||||||
await hon.setup()
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.unique_id] = hon
|
hass.data[DOMAIN][entry.unique_id] = hon
|
||||||
hass.data[DOMAIN]["coordinators"] = {}
|
hass.data[DOMAIN]["coordinators"] = {}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntityDescription, BinarySensorDeviceClass, \
|
from homeassistant.components.binary_sensor import BinarySensorEntityDescription, BinarySensorDeviceClass, \
|
||||||
BinarySensorEntity
|
BinarySensorEntity
|
||||||
|
@ -123,10 +123,10 @@ BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = {
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from homeassistant.components.button import ButtonEntityDescription, ButtonEntity
|
from homeassistant.components.button import ButtonEntityDescription, ButtonEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
from pyhon.device import HonDevice
|
from pyhon.appliance import HonAppliance
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonCoordinator, HonEntity
|
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:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
@ -46,7 +46,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
||||||
|
|
||||||
|
|
||||||
class HonButtonEntity(HonEntity, ButtonEntity):
|
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)
|
super().__init__(hass, entry, coordinator, device)
|
||||||
|
|
||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from pyhon.device import HonDevice
|
from pyhon.appliance import HonAppliance
|
||||||
|
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
@ -15,7 +15,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
class HonEntity(CoordinatorEntity):
|
class HonEntity(CoordinatorEntity):
|
||||||
_attr_has_entity_name = True
|
_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)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self._hon = hass.data[DOMAIN][entry.unique_id]
|
self._hon = hass.data[DOMAIN][entry.unique_id]
|
||||||
|
@ -36,7 +36,7 @@ class HonEntity(CoordinatorEntity):
|
||||||
|
|
||||||
|
|
||||||
class HonCoordinator(DataUpdateCoordinator):
|
class HonCoordinator(DataUpdateCoordinator):
|
||||||
def __init__(self, hass, device: HonDevice):
|
def __init__(self, hass, device: HonAppliance):
|
||||||
"""Initialize my coordinator."""
|
"""Initialize my coordinator."""
|
||||||
super().__init__(hass, _LOGGER, name=device.mac_address, update_interval=timedelta(seconds=30))
|
super().__init__(hass, _LOGGER, name=device.mac_address, update_interval=timedelta(seconds=30))
|
||||||
self._device = device
|
self._device = device
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"documentation": "https://github.com/Andre0512/hon/",
|
"documentation": "https://github.com/Andre0512/hon/",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"issue_tracker": "https://github.com/Andre0512/hon/issues",
|
"issue_tracker": "https://github.com/Andre0512/hon/issues",
|
||||||
"requirements": ["pyhOn==0.4.1"],
|
"requirements": ["pyhOn==0.6.0"],
|
||||||
"version": "0.4.0"
|
"version": "0.5.0-beta.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
from pyhon.parameter import HonParameterRange
|
from pyhon.parameter import HonParameterRange
|
||||||
|
|
||||||
from homeassistant.components.number import (
|
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:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
from pyhon.device import HonDevice
|
from pyhon.appliance import HonAppliance
|
||||||
from pyhon.parameter import HonParameterFixed
|
from pyhon.parameter import HonParameterFixed
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
|
@ -79,10 +79,10 @@ SELECTS = {
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
@ -101,7 +101,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
||||||
|
|
||||||
|
|
||||||
class HonSelectEntity(HonEntity, SelectEntity):
|
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)
|
super().__init__(hass, entry, coordinator, device)
|
||||||
|
|
||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
@ -231,10 +231,10 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> None:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,8 +6,8 @@ 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.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from pyhon import HonConnection
|
from pyhon import Hon
|
||||||
from pyhon.device import HonDevice
|
from pyhon.appliance import HonAppliance
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .hon import HonCoordinator, HonEntity
|
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:
|
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"]
|
coordinators = hass.data[DOMAIN]["coordinators"]
|
||||||
appliances = []
|
appliances = []
|
||||||
for device in hon.devices:
|
for device in hon.appliances:
|
||||||
if device.mac_address in coordinators:
|
if device.mac_address in coordinators:
|
||||||
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
coordinator = hass.data[DOMAIN]["coordinators"][device.mac_address]
|
||||||
else:
|
else:
|
||||||
|
@ -119,7 +119,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
||||||
class HonSwitchEntity(HonEntity, SwitchEntity):
|
class HonSwitchEntity(HonEntity, SwitchEntity):
|
||||||
entity_description: HonSwitchEntityDescription
|
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)
|
super().__init__(hass, entry, coordinator, device)
|
||||||
self._coordinator = coordinator
|
self._coordinator = coordinator
|
||||||
self._device = device
|
self._device = device
|
||||||
|
|
Loading…
Reference in New Issue