Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for Abode Security System entities."""
2 
3 from jaraco.abode.automation import Automation as AbodeAuto
4 from jaraco.abode.devices.base import Device as AbodeDev
5 
6 from homeassistant.helpers.device_registry import DeviceInfo
7 from homeassistant.helpers.entity import Entity
8 
9 from . import AbodeSystem
10 from .const import ATTRIBUTION, DOMAIN
11 
12 
14  """Representation of an Abode entity."""
15 
16  _attr_attribution = ATTRIBUTION
17  _attr_has_entity_name = True
18 
19  def __init__(self, data: AbodeSystem) -> None:
20  """Initialize Abode entity."""
21  self._data_data = data
22  self._attr_should_poll_attr_should_poll = data.polling
23 
24  async def async_added_to_hass(self) -> None:
25  """Subscribe to Abode connection status updates."""
26  await self.hasshass.async_add_executor_job(
27  self._data_data.abode.events.add_connection_status_callback,
28  self.unique_idunique_id,
29  self._update_connection_status_update_connection_status,
30  )
31 
32  self.hasshass.data[DOMAIN].entity_ids.add(self.entity_identity_id)
33 
34  async def async_will_remove_from_hass(self) -> None:
35  """Unsubscribe from Abode connection status updates."""
36  await self.hasshass.async_add_executor_job(
37  self._data_data.abode.events.remove_connection_status_callback, self.unique_idunique_id
38  )
39 
40  def _update_connection_status(self) -> None:
41  """Update the entity available property."""
42  self._attr_available_attr_available = self._data_data.abode.events.connected
43  self.schedule_update_ha_stateschedule_update_ha_state()
44 
45 
47  """Representation of an Abode device."""
48 
49  def __init__(self, data: AbodeSystem, device: AbodeDev) -> None:
50  """Initialize Abode device."""
51  super().__init__(data)
52  self._device_device = device
53  self._attr_unique_id_attr_unique_id = device.uuid
54 
55  async def async_added_to_hass(self) -> None:
56  """Subscribe to device events."""
57  await super().async_added_to_hass()
58  await self.hasshass.async_add_executor_job(
59  self._data_data.abode.events.add_device_callback,
60  self._device_device.id,
61  self._update_callback_update_callback,
62  )
63 
64  async def async_will_remove_from_hass(self) -> None:
65  """Unsubscribe from device events."""
66  await super().async_will_remove_from_hass()
67  await self.hasshass.async_add_executor_job(
68  self._data_data.abode.events.remove_all_device_callbacks, self._device_device.id
69  )
70 
71  def update(self) -> None:
72  """Update device state."""
73  self._device_device.refresh()
74 
75  @property
76  def extra_state_attributes(self) -> dict[str, str]:
77  """Return the state attributes."""
78  return {
79  "device_id": self._device_device.id,
80  "battery_low": self._device_device.battery_low,
81  "no_response": self._device_device.no_response,
82  "device_type": self._device_device.type,
83  }
84 
85  @property
86  def device_info(self) -> DeviceInfo:
87  """Return device registry information for this entity."""
88  return DeviceInfo(
89  identifiers={(DOMAIN, self._device_device.id)},
90  manufacturer="Abode",
91  model=self._device_device.type,
92  name=self._device_device.name,
93  )
94 
95  def _update_callback(self, device: AbodeDev) -> None:
96  """Update the device state."""
97  self.schedule_update_ha_stateschedule_update_ha_state()
98 
99 
101  """Representation of an Abode automation."""
102 
103  def __init__(self, data: AbodeSystem, automation: AbodeAuto) -> None:
104  """Initialize for Abode automation."""
105  super().__init__(data)
106  self._automation_automation = automation
107  self._attr_name_attr_name = automation.name
108  self._attr_unique_id_attr_unique_id = automation.id
109  self._attr_extra_state_attributes_attr_extra_state_attributes = {
110  "type": "CUE automation",
111  }
112 
113  def update(self) -> None:
114  """Update automation state."""
115  self._automation_automation.refresh()
None __init__(self, AbodeSystem data, AbodeAuto automation)
Definition: entity.py:103
None _update_callback(self, AbodeDev device)
Definition: entity.py:95
None __init__(self, AbodeSystem data, AbodeDev device)
Definition: entity.py:49
None __init__(self, AbodeSystem data)
Definition: entity.py:19
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244