|
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 | | - # Don't show orphaned (no location) thermostat-types |
147 | | - if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None: |
| 138 | + # Don't show orphaned thermostat-types |
| 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 |
|
@@ -225,12 +223,13 @@ def _get_locations(self) -> None: |
225 | 223 | "Error, location Home (building) not found!" |
226 | 224 | ) # pragma: no cover |
227 | 225 |
|
228 | | - def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch: |
| 226 | + def _appliance_info_finder(self, appliance: Appliance) -> Appliance: |
229 | 227 | """Collect info for all appliances found.""" |
230 | | - match appl.pwclass: |
231 | | - case "gateway": |
232 | | - # Collect gateway entity info |
233 | | - return self._appl_gateway_info(appl, appliance) |
| 228 | + match application.type: |
| 229 | + # No longer needed since we have a Gateway |
| 230 | + # case "gateway": |
| 231 | + # # Collect gateway entity info |
| 232 | + # return self._appl_gateway_info(appl, appliance) |
234 | 233 | case _ as dev_class if dev_class in THERMOSTAT_CLASSES: |
235 | 234 | # Collect thermostat entity info |
236 | 235 | return self._appl_thermostat_info(appl, appliance) |
@@ -264,24 +263,14 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch |
264 | 263 | case _: # pragma: no cover |
265 | 264 | return Munch() |
266 | 265 |
|
267 | | - def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch: |
| 266 | + def _appl_gateway_info(self, appliance: Appliance) -> Appliance: |
268 | 267 | """Helper-function for _appliance_info_finder().""" |
269 | | - self._gateway_id = appl.entity_id |
270 | | - locator = "./gateway/firmware_version" |
271 | | - appl.firmware = self._domain_objects.find(locator).text |
272 | | - appl.hardware = self.smile.hw_version |
273 | | - appl.mac = self.smile.mac_address |
274 | | - appl.model = self.smile.model |
275 | | - appl.model_id = self.smile.model_id |
276 | | - appl.name = self.smile.name |
277 | | - appl.vendor_name = "Plugwise" |
| 268 | + self._gateway_id = application.id |
278 | 269 |
|
279 | 270 | # Adam: collect the ZigBee MAC address of the Smile |
280 | | - if self.check_name(ADAM): |
281 | | - if ( |
282 | | - found := self._domain_objects.find(".//protocols/zig_bee_coordinator") |
283 | | - ) is not None: |
284 | | - appl.zigbee_mac = found.find("mac_address").text |
| 271 | + if ADAM in appliance.name: |
| 272 | + if (found := appliance.protocols.zig_bee_coordinator) is not None: |
| 273 | + application.zigbee_mac = found.mac_address |
285 | 274 |
|
286 | 275 | # Also, collect regulation_modes and check for cooling, indicating cooling-mode is present |
287 | 276 | self._reg_allowed_modes = self._get_appl_actuator_modes( |
|
0 commit comments