mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Move hive base entity to separate module (#126095)
This commit is contained in:
parent
c20d07c14a
commit
a9c479a78b
@ -18,15 +18,12 @@ from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
async_dispatcher_connect,
|
|
||||||
async_dispatcher_send,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS
|
from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -139,29 +136,3 @@ def refresh_system[_HiveEntityT: HiveEntity, **_P](
|
|||||||
async_dispatcher_send(self.hass, DOMAIN)
|
async_dispatcher_send(self.hass, DOMAIN)
|
||||||
|
|
||||||
return wrapper
|
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)
|
|
||||||
)
|
|
||||||
|
@ -18,8 +18,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HiveEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
@ -14,8 +14,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HiveEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
@ -21,13 +21,14 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HiveEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_TIME_PERIOD,
|
ATTR_TIME_PERIOD,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_BOOST_HEATING_OFF,
|
SERVICE_BOOST_HEATING_OFF,
|
||||||
SERVICE_BOOST_HEATING_ON,
|
SERVICE_BOOST_HEATING_ON,
|
||||||
)
|
)
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
HIVE_TO_HASS_STATE = {
|
HIVE_TO_HASS_STATE = {
|
||||||
"SCHEDULE": HVACMode.AUTO,
|
"SCHEDULE": HVACMode.AUTO,
|
||||||
|
39
homeassistant/components/hive/entity.py
Normal file
39
homeassistant/components/hive/entity.py
Normal 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)
|
||||||
|
)
|
@ -17,8 +17,9 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
from . import HiveEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import ATTR_MODE, DOMAIN
|
from .const import ATTR_MODE, DOMAIN
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from apyhiveapi import Hive
|
from apyhiveapi import Hive
|
||||||
|
@ -24,8 +24,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import HiveEntity
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
@ -13,8 +13,9 @@ from homeassistant.const import EntityCategory
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HiveEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import ATTR_MODE, DOMAIN
|
from .const import ATTR_MODE, DOMAIN
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import HiveEntity, refresh_system
|
from . import refresh_system
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ONOFF,
|
ATTR_ONOFF,
|
||||||
ATTR_TIME_PERIOD,
|
ATTR_TIME_PERIOD,
|
||||||
@ -24,6 +24,7 @@ from .const import (
|
|||||||
SERVICE_BOOST_HOT_WATER,
|
SERVICE_BOOST_HOT_WATER,
|
||||||
WATER_HEATER_MODES,
|
WATER_HEATER_MODES,
|
||||||
)
|
)
|
||||||
|
from .entity import HiveEntity
|
||||||
|
|
||||||
HOTWATER_NAME = "Hot Water"
|
HOTWATER_NAME = "Hot Water"
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user