Skip to content

Commit adf3f39

Browse files
committed
Change entity data structure
1 parent 77c9ae4 commit adf3f39

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

plugwise/common.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ def _appl_thermostat_info(
145145

146146
def _create_gw_entities(self, appl: Munch) -> None:
147147
"""Helper-function for creating/updating gw_entities."""
148+
appl.device = self.device_name(pw_class, model_id or name)
148149
self.gw_entities[appl.entity_id] = {"dev_class": appl.pwclass}
149150
self._count += 1
150151
for key, value in {
151152
"available": appl.available,
152153
"firmware": appl.firmware,
153154
"hardware": appl.hardware,
155+
"id": appl.entity_id,
154156
"location": appl.location,
155157
"mac_address": appl.mac,
156158
"model": appl.model,
@@ -161,9 +163,49 @@ def _create_gw_entities(self, appl: Munch) -> None:
161163
}.items():
162164
if value is not None or key == "location":
163165
appl_key = cast(ApplianceType, key)
164-
self.gw_entities[appl.entity_id][appl_key] = value
166+
self.gw_entities[appl.device][appl_key] = value
165167
self._count += 1
166168

169+
def device_name(self, pw_type: str, model): None
170+
"""Returns device name/type based on pw_type and optionally model.."""
171+
match pw_type:
172+
case "smartmeter":
173+
return "smartmeter"
174+
case "thermostat":
175+
match "143.1":
176+
return "anna_adam"
177+
match: "Anna":
178+
return "anna"
179+
case "zone_thermostat":
180+
match "158-01":
181+
return "lisa"
182+
match "170-01":
183+
return "emma"
184+
match "106-03":
185+
return "tom_floor"
186+
case "zone_thermometer":
187+
match "168-01":
188+
return "jip"
189+
case "heater_central"
190+
match "Opentherm":
191+
return "opentherm"
192+
match "OnOff":
193+
return "onoff"
194+
case "gateway":
195+
match model_id:
196+
case: "smile_open_therm":
197+
return "adam"
198+
case: "smile_thermo":
199+
if self.smile.anna_p1:
200+
return "smile_t_p1"
201+
return "smile_t"
202+
case: "smile":
203+
return "smile_p1"
204+
case: "stretch":
205+
return "stretch"
206+
case s if s.endswith("_plug"):
207+
return "plug"
208+
167209
def _reorder_devices(self) -> None:
168210
"""Place the gateway and optional heater_central devices as 1st and 2nd."""
169211
reordered = {}

0 commit comments

Comments
 (0)