Move hive base entity to separate module (#126095)

pull/126128/head
epenet 2024-09-17 15:44:52 +02:00 committed by GitHub
parent c20d07c14a
commit a9c479a78b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 53 additions and 39 deletions

View File

@ -18,15 +18,12 @@ from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client, config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntry, DeviceInfo
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS
from .entity import HiveEntity
_LOGGER = logging.getLogger(__name__)
@ -139,29 +136,3 @@ def refresh_system[_HiveEntityT: HiveEntity, **_P](
async_dispatcher_send(self.hass, DOMAIN)
return wrapper
class HiveEntity(Entity):
"""Initiate Hive Base Class."""
def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
"""Initialize the instance."""
self.hive = hive
self.device = hive_device
self._attr_name = self.device["haName"]
self._attr_unique_id = f'{self.device["hiveID"]}-{self.device["hiveType"]}'
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)
self.attributes: dict[str, Any] = {}
async def async_added_to_hass(self) -> None:
"""When entity is added to Home Assistant."""
self.async_on_remove(
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
)

View File

@ -18,8 +18,8 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity
from .const import DOMAIN
from .entity import HiveEntity
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)

View File

@ -14,8 +14,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity
from .const import DOMAIN
from .entity import HiveEntity
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)

View File

@ -21,13 +21,14 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity, refresh_system
from . import refresh_system
from .const import (
ATTR_TIME_PERIOD,
DOMAIN,
SERVICE_BOOST_HEATING_OFF,
SERVICE_BOOST_HEATING_ON,
)
from .entity import HiveEntity
HIVE_TO_HASS_STATE = {
"SCHEDULE": HVACMode.AUTO,

View File

@ -0,0 +1,39 @@
"""Support for the Hive devices and services."""
from __future__ import annotations
from typing import Any
from apyhiveapi import Hive
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from .const import DOMAIN
class HiveEntity(Entity):
"""Initiate Hive Base Class."""
def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
"""Initialize the instance."""
self.hive = hive
self.device = hive_device
self._attr_name = self.device["haName"]
self._attr_unique_id = f'{self.device["hiveID"]}-{self.device["hiveType"]}'
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)
self.attributes: dict[str, Any] = {}
async def async_added_to_hass(self) -> None:
"""When entity is added to Home Assistant."""
self.async_on_remove(
async_dispatcher_connect(self.hass, DOMAIN, self.async_write_ha_state)
)

View File

@ -17,8 +17,9 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.color as color_util
from . import HiveEntity, refresh_system
from . import refresh_system
from .const import ATTR_MODE, DOMAIN
from .entity import HiveEntity
if TYPE_CHECKING:
from apyhiveapi import Hive

View File

@ -24,8 +24,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import HiveEntity
from .const import DOMAIN
from .entity import HiveEntity
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)

View File

@ -13,8 +13,9 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity, refresh_system
from . import refresh_system
from .const import ATTR_MODE, DOMAIN
from .entity import HiveEntity
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)

View File

@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HiveEntity, refresh_system
from . import refresh_system
from .const import (
ATTR_ONOFF,
ATTR_TIME_PERIOD,
@ -24,6 +24,7 @@ from .const import (
SERVICE_BOOST_HOT_WATER,
WATER_HEATER_MODES,
)
from .entity import HiveEntity
HOTWATER_NAME = "Hot Water"
PARALLEL_UPDATES = 0