Skip to content

Commit 8a4202b

Browse files
committed
Improve detection and error-handling for home-location
1 parent 3400aad commit 8a4202b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

plugwise/helper.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,32 @@ def _get_p1_smartmeter_info(self) -> None:
202202

203203
def _get_locations(self) -> None:
204204
"""Collect all locations."""
205+
counter = 0
205206
loc = Munch()
206207
locations = self._domain_objects.findall("./location")
207208
for location in locations:
208209
loc.loc_id = location.attrib["id"]
209210
loc.name = location.find("name").text
211+
loc._type = location.find("type").text
210212
self._loc_data[loc.loc_id] = {
211213
"name": loc.name,
212214
"primary": [],
213215
"primary_prio": 0,
214216
"secondary": [],
215217
}
216-
if loc.name == "Home":
218+
# Home location is of type building
219+
if loc._type == "building":
220+
counter += 1
217221
self._home_loc_id = loc.loc_id
218222
self._home_location = self._domain_objects.find(
219223
f"./location[@id='{loc.loc_id}']"
220224
)
221225

226+
if counter == 0:
227+
raise KeyError(
228+
"Error, location Home (building) not found!"
229+
) # pragma: no cover
230+
222231
def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch:
223232
"""Collect info for all appliances found."""
224233
match appl.pwclass:

0 commit comments

Comments
 (0)