diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e6bbfec..8f0031e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Ongoing -- Code optimizations via PR [#837](https://github.com/plugwise/python-plugwise/pull/837), [#838](https://github.com/plugwise/python-plugwise/pull/838), [#839](https://github.com/plugwise/python-plugwise/pull/839) +- Code optimizations via PR [#837](https://github.com/plugwise/python-plugwise/pull/837), [#838](https://github.com/plugwise/python-plugwise/pull/838), [#839](https://github.com/plugwise/python-plugwise/pull/839), [#840](https://github.com/plugwise/python-plugwise/pull/840) ## v1.11.0 diff --git a/plugwise/helper.py b/plugwise/helper.py index 371dd1613..2bd16bf42 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -118,14 +118,14 @@ def _get_appliances(self) -> None: appl = Munch() appl.available = None appl.entity_id = appliance.get("id") + appl.firmware = None + appl.hardware = None appl.location = None - appl.name = appliance.find("name").text + appl.mac = None appl.model = None appl.model_id = None appl.module_id = None - appl.firmware = None - appl.hardware = None - appl.mac = None + appl.name = appliance.find("name").text appl.pwclass = appliance.find("type").text appl.zigbee_mac = None appl.vendor_name = None @@ -205,6 +205,9 @@ def _get_locations(self) -> None: counter = 0 loc = Munch() locations = self._domain_objects.findall("./location") + if not locations: + raise KeyError("No location data present!") + for location in locations: loc.loc_id = location.get("id") loc.name = location.find("name").text diff --git a/plugwise/legacy/helper.py b/plugwise/legacy/helper.py index 3ec6d0632..4f3c806c3 100644 --- a/plugwise/legacy/helper.py +++ b/plugwise/legacy/helper.py @@ -83,10 +83,10 @@ def item_count(self) -> int: """Return the item-count.""" return self._count - def _all_appliances(self) -> None: + def _get_appliances(self) -> None: """Collect all appliances with relevant info.""" self._count = 0 - self._all_locations() + self._get_locations() self._create_legacy_gateway() # For legacy P1 collect the connected SmartMeter info @@ -99,6 +99,19 @@ def _all_appliances(self) -> None: for appliance in self._appliances.findall("./appliance"): appl = Munch() appl.pwclass = appliance.find("type").text + + appl.available = None + appl.entity_id = appliance.get("id") + appl.firmware = None + appl.hardware = None + appl.location = self._home_loc_id + appl.mac = None + appl.model = appl.pwclass.replace("_", " ").title() + appl.model_id = None + appl.name = appliance.find("name").text + appl.vendor_name = None + appl.zigbee_mac = None + # Skip thermostats that have this key, should be an orphaned device (Core #81712) if ( appl.pwclass == "thermostat" @@ -106,9 +119,6 @@ def _all_appliances(self) -> None: ): continue # pragma: no cover - appl.location = self._home_loc_id - appl.entity_id = appliance.get("id") - appl.name = appliance.find("name").text # Extend device_class name when a Circle/Stealth is type heater_central -- Pw-Beta Issue #739 if ( appl.pwclass == "heater_central" @@ -116,15 +126,6 @@ def _all_appliances(self) -> None: ): appl.pwclass = "heater_central_plug" - appl.model = appl.pwclass.replace("_", " ").title() - appl.available = None - appl.model_id = None - appl.firmware = None - appl.hardware = None - appl.mac = None - appl.zigbee_mac = None - appl.vendor_name = None - # Determine class for this appliance # Skip on heater_central when no active device present or on orphaned stretch devices if not (appl := self._appliance_info_finder(appliance, appl)): @@ -137,7 +138,7 @@ def _all_appliances(self) -> None: self._create_gw_entities(appl) self._reorder_devices() - def _all_locations(self) -> None: + def _get_locations(self) -> None: """Collect all locations.""" loc = Munch() diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index a841a1d1c..9b97f2501 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -81,7 +81,7 @@ def get_all_gateway_entities(self) -> None: Collect and add switching- and/or pump-group entities. Finally, collect the data and states for each entity. """ - self._all_appliances() + self._get_appliances() self._get_groups() self._all_entity_data() diff --git a/plugwise/smile.py b/plugwise/smile.py index 61a042964..d6c10f826 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -137,8 +137,6 @@ async def async_update(self) -> dict[str, GwEntityData]: self._cooling_enabled = heat_cooler["binary_sensors"][ "cooling_enabled" ] - else: # cover failed data-retrieval for P1 - _ = self.gw_entities[self.gateway_id]["location"] except KeyError as err: raise DataMissingError("No Plugwise actual data received") from err