Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """DataUpdate Coordinator, and base Entity and Device models for Toon."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.update_coordinator import CoordinatorEntity
9 
10 from .const import DOMAIN
11 from .coordinator import ToonDataUpdateCoordinator
12 
13 
14 class ToonEntity(CoordinatorEntity[ToonDataUpdateCoordinator]):
15  """Defines a base Toon entity."""
16 
17 
19  """Defines a Toon display device entity."""
20 
21  @property
22  def device_info(self) -> DeviceInfo:
23  """Return device information about this thermostat."""
24  agreement = self.coordinator.data.agreement
25  return DeviceInfo(
26  identifiers={(DOMAIN, agreement.agreement_id)},
27  manufacturer="Eneco",
28  model=agreement.display_hardware_version.rpartition("/")[0],
29  name="Toon Display",
30  sw_version=agreement.display_software_version.rpartition("/")[-1],
31  )
32 
33 
35  """Defines a Electricity Meter device entity."""
36 
37  @property
38  def device_info(self) -> DeviceInfo:
39  """Return device information about this entity."""
40  agreement_id = self.coordinator.data.agreement.agreement_id
41  return DeviceInfo(
42  name="Electricity Meter",
43  identifiers={
44  (DOMAIN, agreement_id, "electricity"), # type: ignore[arg-type]
45  },
46  via_device=(
47  DOMAIN,
48  agreement_id, # type: ignore[typeddict-item]
49  "meter_adapter",
50  ),
51  )
52 
53 
55  """Defines a Gas Meter device entity."""
56 
57  @property
58  def device_info(self) -> DeviceInfo:
59  """Return device information about this entity."""
60  agreement_id = self.coordinator.data.agreement.agreement_id
61  return DeviceInfo(
62  name="Gas Meter",
63  identifiers={
64  (DOMAIN, agreement_id, "gas"), # type: ignore[arg-type]
65  },
66  via_device=(
67  DOMAIN,
68  agreement_id, # type: ignore[typeddict-item]
69  "electricity",
70  ),
71  )
72 
73 
75  """Defines a Water Meter device entity."""
76 
77  @property
78  def device_info(self) -> DeviceInfo:
79  """Return device information about this entity."""
80  agreement_id = self.coordinator.data.agreement.agreement_id
81  return DeviceInfo(
82  name="Water Meter",
83  identifiers={
84  (DOMAIN, agreement_id, "water"), # type: ignore[arg-type]
85  },
86  via_device=(
87  DOMAIN,
88  agreement_id, # type: ignore[typeddict-item]
89  "electricity",
90  ),
91  )
92 
93 
95  """Defines a Solar Device device entity."""
96 
97  @property
98  def device_info(self) -> DeviceInfo:
99  """Return device information about this entity."""
100  agreement_id = self.coordinator.data.agreement.agreement_id
101  return DeviceInfo(
102  name="Solar Panels",
103  identifiers={
104  (DOMAIN, agreement_id, "solar"), # type: ignore[arg-type]
105  },
106  via_device=(
107  DOMAIN,
108  agreement_id, # type: ignore[typeddict-item]
109  "meter_adapter",
110  ),
111  )
112 
113 
115  """Defines a Boiler Module device entity."""
116 
117  @property
118  def device_info(self) -> DeviceInfo:
119  """Return device information about this entity."""
120  agreement_id = self.coordinator.data.agreement.agreement_id
121  return DeviceInfo(
122  name="Boiler Module",
123  manufacturer="Eneco",
124  identifiers={
125  (
126  DOMAIN,
127  agreement_id, # type: ignore[arg-type]
128  "boiler_module",
129  )
130  },
131  via_device=(DOMAIN, agreement_id),
132  )
133 
134 
136  """Defines a Boiler device entity."""
137 
138  @property
139  def device_info(self) -> DeviceInfo:
140  """Return device information about this entity."""
141  agreement_id = self.coordinator.data.agreement.agreement_id
142  return DeviceInfo(
143  name="Boiler",
144  identifiers={
145  (DOMAIN, agreement_id, "boiler"), # type: ignore[arg-type]
146  },
147  via_device=(
148  DOMAIN,
149  agreement_id, # type: ignore[typeddict-item]
150  "boiler_module",
151  ),
152  )
153 
154 
155 @dataclass(frozen=True)
157  """Mixin for required keys."""
158 
159  section: str
160  measurement: str