Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for the Hive devices and services."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from apyhiveapi import Hive
8 
9 from homeassistant.helpers.device_registry import DeviceInfo
10 from homeassistant.helpers.dispatcher import async_dispatcher_connect
11 from homeassistant.helpers.entity import Entity
12 
13 from .const import DOMAIN
14 
15 
17  """Initiate Hive Base Class."""
18 
19  def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
20  """Initialize the instance."""
21  self.hivehive = hive
22  self.devicedevice = hive_device
23  self._attr_name_attr_name = self.devicedevice["haName"]
24  self._attr_unique_id_attr_unique_id = f'{self.device["hiveID"]}-{self.device["hiveType"]}'
25  self._attr_device_info_attr_device_info = DeviceInfo(
26  identifiers={(DOMAIN, self.devicedevice["device_id"])},
27  model=self.devicedevice["deviceData"]["model"],
28  manufacturer=self.devicedevice["deviceData"]["manufacturer"],
29  name=self.devicedevice["device_name"],
30  sw_version=self.devicedevice["deviceData"]["version"],
31  via_device=(DOMAIN, self.devicedevice["parentDevice"]),
32  )
33  self.attributes: dict[str, Any] = {}
34 
35  async def async_added_to_hass(self) -> None:
36  """When entity is added to Home Assistant."""
37  self.async_on_removeasync_on_remove(
38  async_dispatcher_connect(self.hasshass, DOMAIN, self.async_write_ha_stateasync_write_ha_state)
39  )
None __init__(self, Hive hive, dict[str, Any] hive_device)
Definition: entity.py:19
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103