Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entity for the system bridge integration."""
2 
3 from homeassistant.helpers import device_registry as dr
4 from homeassistant.helpers.device_registry import DeviceInfo
5 from homeassistant.helpers.update_coordinator import CoordinatorEntity
6 
7 from .const import DOMAIN
8 from .coordinator import SystemBridgeDataUpdateCoordinator
9 
10 
11 class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]):
12  """Defines a base System Bridge entity."""
13 
14  _attr_has_entity_name = True
15 
16  def __init__(
17  self,
18  coordinator: SystemBridgeDataUpdateCoordinator,
19  api_port: int,
20  key: str,
21  ) -> None:
22  """Initialize the System Bridge entity."""
23  super().__init__(coordinator)
24 
25  self._hostname_hostname = coordinator.data.system.hostname
26  self._key_key = f"{self._hostname}_{key}"
27  self._configuration_url_configuration_url = (
28  f"http://{self._hostname}:{api_port}/app/settings.html"
29  )
30  self._mac_address_mac_address = coordinator.data.system.mac_address
31  self._uuid_uuid = coordinator.data.system.uuid
32  self._version_version = coordinator.data.system.version
33 
34  @property
35  def unique_id(self) -> str:
36  """Return the unique ID for this entity."""
37  return self._key_key
38 
39  @property
40  def device_info(self) -> DeviceInfo:
41  """Return device information about this System Bridge instance."""
42  return DeviceInfo(
43  configuration_url=self._configuration_url_configuration_url,
44  connections={(dr.CONNECTION_NETWORK_MAC, self._mac_address_mac_address)},
45  identifiers={(DOMAIN, self._uuid_uuid)},
46  name=self._hostname_hostname,
47  sw_version=self._version_version,
48  )
None __init__(self, SystemBridgeDataUpdateCoordinator coordinator, int api_port, str key)
Definition: entity.py:21