Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base Entity for Kaleidescape."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import TYPE_CHECKING
7 
8 from homeassistant.core import callback
9 from homeassistant.helpers.device_registry import DeviceInfo
10 from homeassistant.helpers.entity import Entity
11 
12 from .const import DOMAIN as KALEIDESCAPE_DOMAIN, NAME as KALEIDESCAPE_NAME
13 
14 if TYPE_CHECKING:
15  from kaleidescape import Device as KaleidescapeDevice
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 
21  """Defines a base Kaleidescape entity."""
22 
23  _attr_has_entity_name = True
24  _attr_should_poll = False
25 
26  def __init__(self, device: KaleidescapeDevice) -> None:
27  """Initialize entity."""
28  self._device_device = device
29 
30  self._attr_unique_id_attr_unique_id = device.serial_number
31  self._attr_device_info_attr_device_info = DeviceInfo(
32  identifiers={(KALEIDESCAPE_DOMAIN, self._device_device.serial_number)},
33  # Instead of setting the device name to the entity name, kaleidescape
34  # should be updated to set has_entity_name = True
35  name=f"{KALEIDESCAPE_NAME} {device.system.friendly_name}",
36  model=self._device_device.system.type,
37  manufacturer=KALEIDESCAPE_NAME,
38  sw_version=f"{self._device.system.kos_version}",
39  suggested_area="Theater",
40  configuration_url=f"http://{self._device.host}",
41  )
42 
43  async def async_added_to_hass(self) -> None:
44  """Register update listener."""
45 
46  @callback
47  def _update(event: str) -> None:
48  """Handle device state changes."""
49  self.async_write_ha_stateasync_write_ha_state()
50 
51  self.async_on_removeasync_on_remove(self._device_device.dispatcher.connect(_update).disconnect)
None __init__(self, KaleidescapeDevice device)
Definition: entity.py:26
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331