Skip to content

Commit 6e8a497

Browse files
authored
Merge pull request #840 from plugwise/alt-reboot
Optimize code 4
2 parents fa40d6d + 1a9ed04 commit 6e8a497

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Ongoing
44

5-
- 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)
5+
- 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)
66

77
## v1.11.0
88

plugwise/helper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ def _get_appliances(self) -> None:
118118
appl = Munch()
119119
appl.available = None
120120
appl.entity_id = appliance.get("id")
121+
appl.firmware = None
122+
appl.hardware = None
121123
appl.location = None
122-
appl.name = appliance.find("name").text
124+
appl.mac = None
123125
appl.model = None
124126
appl.model_id = None
125127
appl.module_id = None
126-
appl.firmware = None
127-
appl.hardware = None
128-
appl.mac = None
128+
appl.name = appliance.find("name").text
129129
appl.pwclass = appliance.find("type").text
130130
appl.zigbee_mac = None
131131
appl.vendor_name = None
@@ -205,6 +205,9 @@ def _get_locations(self) -> None:
205205
counter = 0
206206
loc = Munch()
207207
locations = self._domain_objects.findall("./location")
208+
if not locations:
209+
raise KeyError("No location data present!")
210+
208211
for location in locations:
209212
loc.loc_id = location.get("id")
210213
loc.name = location.find("name").text

plugwise/legacy/helper.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def item_count(self) -> int:
8383
"""Return the item-count."""
8484
return self._count
8585

86-
def _all_appliances(self) -> None:
86+
def _get_appliances(self) -> None:
8787
"""Collect all appliances with relevant info."""
8888
self._count = 0
89-
self._all_locations()
89+
self._get_locations()
9090

9191
self._create_legacy_gateway()
9292
# For legacy P1 collect the connected SmartMeter info
@@ -99,32 +99,33 @@ def _all_appliances(self) -> None:
9999
for appliance in self._appliances.findall("./appliance"):
100100
appl = Munch()
101101
appl.pwclass = appliance.find("type").text
102+
103+
appl.available = None
104+
appl.entity_id = appliance.get("id")
105+
appl.firmware = None
106+
appl.hardware = None
107+
appl.location = self._home_loc_id
108+
appl.mac = None
109+
appl.model = appl.pwclass.replace("_", " ").title()
110+
appl.model_id = None
111+
appl.name = appliance.find("name").text
112+
appl.vendor_name = None
113+
appl.zigbee_mac = None
114+
102115
# Skip thermostats that have this key, should be an orphaned device (Core #81712)
103116
if (
104117
appl.pwclass == "thermostat"
105118
and appliance.find("actuator_functionalities/") is None
106119
):
107120
continue # pragma: no cover
108121

109-
appl.location = self._home_loc_id
110-
appl.entity_id = appliance.get("id")
111-
appl.name = appliance.find("name").text
112122
# Extend device_class name when a Circle/Stealth is type heater_central -- Pw-Beta Issue #739
113123
if (
114124
appl.pwclass == "heater_central"
115125
and appl.name != "Central heating boiler"
116126
):
117127
appl.pwclass = "heater_central_plug"
118128

119-
appl.model = appl.pwclass.replace("_", " ").title()
120-
appl.available = None
121-
appl.model_id = None
122-
appl.firmware = None
123-
appl.hardware = None
124-
appl.mac = None
125-
appl.zigbee_mac = None
126-
appl.vendor_name = None
127-
128129
# Determine class for this appliance
129130
# Skip on heater_central when no active device present or on orphaned stretch devices
130131
if not (appl := self._appliance_info_finder(appliance, appl)):
@@ -137,7 +138,7 @@ def _all_appliances(self) -> None:
137138
self._create_gw_entities(appl)
138139
self._reorder_devices()
139140

140-
def _all_locations(self) -> None:
141+
def _get_locations(self) -> None:
141142
"""Collect all locations."""
142143
loc = Munch()
143144

plugwise/legacy/smile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_all_gateway_entities(self) -> None:
8181
Collect and add switching- and/or pump-group entities.
8282
Finally, collect the data and states for each entity.
8383
"""
84-
self._all_appliances()
84+
self._get_appliances()
8585
self._get_groups()
8686
self._all_entity_data()
8787

plugwise/smile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ async def async_update(self) -> dict[str, GwEntityData]:
137137
self._cooling_enabled = heat_cooler["binary_sensors"][
138138
"cooling_enabled"
139139
]
140-
else: # cover failed data-retrieval for P1
141-
_ = self.gw_entities[self.gateway_id]["location"]
142140
except KeyError as err:
143141
raise DataMissingError("No Plugwise actual data received") from err
144142

0 commit comments

Comments
 (0)