Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entities for Sense energy."""
2 
3 from sense_energy import ASyncSenseable
4 from sense_energy.sense_api import SenseDevice
5 
6 from homeassistant.helpers.device_registry import DeviceInfo
7 from homeassistant.helpers.update_coordinator import CoordinatorEntity
8 
9 from .const import ATTRIBUTION, DOMAIN, MDI_ICONS
10 from .coordinator import SenseCoordinator
11 
12 
13 def sense_to_mdi(sense_icon: str) -> str:
14  """Convert sense icon to mdi icon."""
15  return f"mdi:{MDI_ICONS.get(sense_icon, "power-plug")}"
16 
17 
18 class SenseEntity(CoordinatorEntity[SenseCoordinator]):
19  """Base implementation of a Sense sensor."""
20 
21  _attr_attribution = ATTRIBUTION
22  _attr_should_poll = False
23  _attr_has_entity_name = True
24 
25  def __init__(
26  self,
27  gateway: ASyncSenseable,
28  coordinator: SenseCoordinator,
29  sense_monitor_id: str,
30  unique_id: str,
31  ) -> None:
32  """Initialize the Sense sensor."""
33  super().__init__(coordinator)
34  self._attr_unique_id_attr_unique_id = f"{sense_monitor_id}-{unique_id}"
35  self._gateway_gateway_gateway = gateway
36  self._attr_device_info_attr_device_info = DeviceInfo(
37  name=f"Sense {sense_monitor_id}",
38  identifiers={(DOMAIN, sense_monitor_id)},
39  model="Sense",
40  manufacturer="Sense Labs, Inc.",
41  configuration_url="https://home.sense.com",
42  )
43 
44 
45 class SenseDeviceEntity(CoordinatorEntity[SenseCoordinator]):
46  """Base implementation of a Sense sensor."""
47 
48  _attr_attribution = ATTRIBUTION
49  _attr_should_poll = False
50  _attr_has_entity_name = True
51 
52  def __init__(
53  self,
54  device: SenseDevice,
55  coordinator: SenseCoordinator,
56  sense_monitor_id: str,
57  unique_id: str,
58  ) -> None:
59  """Initialize the Sense sensor."""
60  super().__init__(coordinator)
61  self._attr_unique_id_attr_unique_id = f"{sense_monitor_id}-{unique_id}"
62  self._device_device = device
63  self._attr_icon_attr_icon = sense_to_mdi(device.icon)
64  self._attr_device_info_attr_device_info = DeviceInfo(
65  name=device.name,
66  identifiers={(DOMAIN, f"{sense_monitor_id}:{device.id}")},
67  model="Sense",
68  manufacturer="Sense Labs, Inc.",
69  configuration_url="https://home.sense.com",
70  via_device=(DOMAIN, sense_monitor_id),
71  )
None __init__(self, SenseDevice device, SenseCoordinator coordinator, str sense_monitor_id, str unique_id)
Definition: entity.py:58
None __init__(self, ASyncSenseable gateway, SenseCoordinator coordinator, str sense_monitor_id, str unique_id)
Definition: entity.py:31
str sense_to_mdi(str sense_icon)
Definition: entity.py:13