|
43 | 43 | ThermoLoc, |
44 | 44 | ToggleNameType, |
45 | 45 | ) |
| 46 | +from plugwise.model import Appliance, ApplianceType, OffsetFunctionality |
46 | 47 | from plugwise.util import ( |
47 | 48 | check_model, |
48 | 49 | collect_power_values, |
|
57 | 58 | from packaging import version |
58 | 59 |
|
59 | 60 |
|
60 | | -def extend_plug_device_class(appl: Munch, appliance: etree.Element) -> None: |
61 | | - """Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739.""" |
62 | | - |
63 | | - if (description := appliance.description) is not None and ( |
64 | | - "ZigBee protocol" in description or "smart plug" in description |
65 | | - ): |
66 | | - appl.pwclass = f"{appl.pwclass}_plug" |
67 | | - |
68 | | - |
69 | 61 | def search_actuator_functionalities( |
70 | 62 | appliance: etree.Element, actuator: str |
71 | 63 | ) -> etree.Element | None: |
@@ -130,28 +122,34 @@ def _get_appliances(self) -> None: |
130 | 122 |
|
131 | 123 | # Don't collect data for the OpenThermGateway appliance, skip thermostat(s) |
132 | 124 | # without actuator_functionalities, should be an orphaned device(s) (Core #81712) |
133 | | - if appl.pwclass == "open_therm_gateway" or ( |
134 | | - appl.pwclass == "thermostat" |
135 | | - and appliance.find("actuator_functionalities/") is None |
| 125 | + if appliance.type == ApplianceType.OPENTHERMGW or ( |
| 126 | + appliance.type == ApplianceType.THERMOSTAT |
| 127 | + and appliance.actuator_functionalities is None |
136 | 128 | ): |
137 | 129 | continue |
138 | 130 |
|
139 | | - if (appl_loc := appliance.location) is not None: |
140 | | - appl.location = appl_loc.get("id") |
| 131 | + if appliance.location is not None: |
| 132 | + appl.fixed_location = appliance.id |
141 | 133 | # Set location to the _home_loc_id when the appliance-location is not found, |
142 | 134 | # except for thermostat-devices without a location, they are not active |
143 | | - elif appl.pwclass not in THERMOSTAT_CLASSES: |
144 | | - appl.location = self._home_loc_id |
| 135 | + elif appliance.type not in THERMOSTAT_CLASSES: |
| 136 | + appliance.fixed_location = self._home_loc_id |
145 | 137 |
|
146 | 138 | # Don't show orphaned thermostat-types |
147 | | - if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None: |
| 139 | + if appliance.type in THERMOSTAT_CLASSES and appliance.location is None: |
148 | 140 | continue |
149 | 141 |
|
150 | | - extend_plug_device_class(appl, appliance) |
| 142 | + # Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739 |
| 143 | + if appliance.description is not None and ( |
| 144 | + "ZigBee protocol" in appliance.description |
| 145 | + or "smart plug" in appliance.description |
| 146 | + ): |
| 147 | + appliance.type = f"{appliance.type}_plug" |
151 | 148 |
|
152 | | - # Collect appliance info, skip orphaned/removed devices |
153 | | - if not (appl := self._appliance_info_finder(appl, appliance)): |
154 | | - continue |
| 149 | + # TODO: recreate functionality |
| 150 | + # # Collect appliance info, skip orphaned/removed devices |
| 151 | + # if not (appl := self._appliance_info_finder(appl, appliance)): |
| 152 | + # continue |
155 | 153 |
|
156 | 154 | self._create_gw_entities(appl) |
157 | 155 |
|
@@ -230,12 +228,13 @@ def _get_locations(self) -> None: |
230 | 228 | "Error, location Home (building) not found!" |
231 | 229 | ) # pragma: no cover |
232 | 230 |
|
233 | | - def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch: |
| 231 | + def _appliance_info_finder(self, appliance: Appliance) -> Appliance: |
234 | 232 | """Collect info for all appliances found.""" |
235 | | - match appl.pwclass: |
236 | | - case "gateway": |
237 | | - # Collect gateway entity info |
238 | | - return self._appl_gateway_info(appl, appliance) |
| 233 | + match application.type: |
| 234 | + # No longer needed since we have a Gateway |
| 235 | + # case "gateway": |
| 236 | + # # Collect gateway entity info |
| 237 | + # return self._appl_gateway_info(appl, appliance) |
239 | 238 | case _ as dev_class if dev_class in THERMOSTAT_CLASSES: |
240 | 239 | # Collect thermostat entity info |
241 | 240 | return self._appl_thermostat_info(appl, appliance) |
@@ -269,24 +268,14 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch |
269 | 268 | case _: # pragma: no cover |
270 | 269 | return Munch() |
271 | 270 |
|
272 | | - def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch: |
| 271 | + def _appl_gateway_info(self, appliance: Appliance) -> Appliance: |
273 | 272 | """Helper-function for _appliance_info_finder().""" |
274 | | - self._gateway_id = appl.entity_id |
275 | | - locator = "./gateway/firmware_version" |
276 | | - appl.firmware = self._domain_objects.find(locator).text |
277 | | - appl.hardware = self.smile.hw_version |
278 | | - appl.mac = self.smile.mac_address |
279 | | - appl.model = self.smile.model |
280 | | - appl.model_id = self.smile.model_id |
281 | | - appl.name = self.smile.name |
282 | | - appl.vendor_name = "Plugwise" |
| 273 | + self._gateway_id = application.id |
283 | 274 |
|
284 | 275 | # Adam: collect the ZigBee MAC address of the Smile |
285 | | - if self.check_name(ADAM): |
286 | | - if ( |
287 | | - found := self._domain_objects.find(".//protocols/zig_bee_coordinator") |
288 | | - ) is not None: |
289 | | - appl.zigbee_mac = found.find("mac_address").text |
| 276 | + if ADAM in appliance.name: |
| 277 | + if (found := appliance.protocols.zig_bee_coordinator) is not None: |
| 278 | + application.zigbee_mac = found.mac_address |
290 | 279 |
|
291 | 280 | # Also, collect regulation_modes and check for cooling, indicating cooling-mode is present |
292 | 281 | self._reg_allowed_modes = self._get_appl_actuator_modes( |
@@ -317,12 +306,19 @@ def _get_appl_actuator_modes( |
317 | 306 |
|
318 | 307 | def _get_appliances_with_offset_functionality(self) -> list[str]: |
319 | 308 | """Helper-function collecting all appliance that have offset_functionality.""" |
320 | | - therm_list: list[str] = [] |
321 | | - offset_appls = self._domain_objects.findall( |
322 | | - './/actuator_functionalities/offset_functionality[type="temperature_offset"]/offset/../../..' |
323 | | - ) |
324 | | - for item in offset_appls: |
325 | | - therm_list.append(item.get("id")) |
| 309 | + therm_list = [] |
| 310 | + for appl in self._domain_objects.appliance: |
| 311 | + af = appl.actuator_functionalities |
| 312 | + if not af or not isinstance(af, OffsetFunctionality): |
| 313 | + continue |
| 314 | + |
| 315 | + print(f"HOI6 {af}") |
| 316 | + ofs = af.offset_functionality |
| 317 | + if isinstance(ofs, OffsetFunctionality): |
| 318 | + ofs = [ofs] |
| 319 | + |
| 320 | + if any(o.type == "temperature_offset" for o in ofs): |
| 321 | + therm_list.append(appl.id) |
326 | 322 |
|
327 | 323 | return therm_list |
328 | 324 |
|
|
0 commit comments