Skip to content

Commit a3b545c

Browse files
committed
Change entity data structure
1 parent a8c970a commit a3b545c

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
@@ -146,12 +146,14 @@ def _appl_thermostat_info(
146146

147147
def _create_gw_entities(self, appl: Munch) -> None:
148148
"""Helper-function for creating/updating gw_entities."""
149+
appl.device = self.device_name(pw_class, model_id or name)
149150
self.gw_entities[appl.entity_id] = {"dev_class": appl.pwclass}
150151
self._count += 1
151152
for key, value in {
152153
"available": appl.available,
153154
"firmware": appl.firmware,
154155
"hardware": appl.hardware,
156+
"id": appl.entity_id,
155157
"location": appl.location,
156158
"mac_address": appl.mac,
157159
"model": appl.model,
@@ -162,9 +164,49 @@ def _create_gw_entities(self, appl: Munch) -> None:
162164
}.items():
163165
if value is not None or key == "location":
164166
appl_key = cast(ApplianceType, key)
165-
self.gw_entities[appl.entity_id][appl_key] = value
167+
self.gw_entities[appl.device][appl_key] = value
166168
self._count += 1
167169

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

0 commit comments

Comments
 (0)