Skip to content

Commit 5150a7d

Browse files
committed
More reordering, improvements
1 parent 34f2631 commit 5150a7d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

plugwise/helper.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,62 +104,60 @@ def _all_appliances(self) -> None:
104104

105105
for appliance in self._domain_objects.findall("./appliance"):
106106
appl = Munch()
107+
appl.available = None
108+
appl.entity_id = appliance.attrib["id"]
109+
appl.location = None
110+
appl.name = appliance.find("name").text
111+
appl.model = None
112+
appl.model_id = None
113+
appl.firmware = None
114+
appl.hardware = None
115+
appl.mac = None
107116
appl.pwclass = appliance.find("type").text
108-
# Don't collect data for the OpenThermGateway appliance
109-
if appl.pwclass == "open_therm_gateway":
110-
continue
117+
appl.zigbee_mac = None
118+
appl.vendor_name = None
111119

112-
# Skip thermostats that have this key, should be an orphaned device (Core #81712)
113-
if (
120+
# Don't collect data for the OpenThermGateway appliance, skip thermostat(s)
121+
# without actuator_functionalities, should be an orphaned device(s) (Core #81712)
122+
if appl.pwclass == "open_therm_gateway" or (
114123
appl.pwclass == "thermostat"
115124
and appliance.find("actuator_functionalities/") is None
116125
):
117126
continue
118127

119-
appl.location = None
120128
if (appl_loc := appliance.find("location")) is not None:
121129
appl.location = appl_loc.attrib["id"]
122-
# Don't assign the _home_loc_id to thermostat-devices without a location,
123-
# they are not active
130+
# Set location to the _home_loc_id when the appliance-location is not found,
131+
# except for thermostat-devices without a location, they are not active
124132
elif appl.pwclass not in THERMOSTAT_CLASSES:
125133
appl.location = self._home_loc_id
126134

127-
# Don't show orphaned thermostat-types
135+
# Don't show orphaned (no location) thermostat-types
128136
if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None:
129137
continue
130138

131-
appl.available = None
132-
appl.entity_id = appliance.attrib["id"]
133-
appl.name = appliance.find("name").text
134-
appl.model = None
135-
appl.model_id = None
136-
appl.firmware = None
137-
appl.hardware = None
138-
appl.mac = None
139-
appl.zigbee_mac = None
140-
appl.vendor_name = None
141-
142139
# Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739
143140
description = appliance.find("description").text
144141
if description is not None and (
145142
"ZigBee protocol" in description or "smart plug" in description
146143
):
147144
appl.pwclass = f"{appl.pwclass}_plug"
148-
# Collect appliance info, skip orphaned/removed devices
149145

146+
# Collect appliance info, skip orphaned/removed devices
150147
if not (appl := self._appliance_info_finder(appl, appliance)):
151148
continue
152149

153150
self._create_gw_entities(appl)
154151

152+
# A smartmeter is not present as an appliance, add it specifically
155153
if self.smile.type == "power" or self.smile.anna_p1:
156-
self._get_p1_smartmeter_info()
154+
self._add_p1_smartmeter_info()
157155

158156
# Sort the gw_entities
159157
self._reorder_devices()
160158

161-
def _get_p1_smartmeter_info(self) -> None:
162-
"""For P1 collect the connected SmartMeter info from the Home/building location.
159+
def _add_p1_smartmeter_info(self) -> None:
160+
"""For P1 collect the smartmeter info from the Home/building location and add it as an entity.
163161
164162
Note: For P1, the entity_id for the gateway and smartmeter are switched to maintain
165163
backward compatibility. For Anna P1, the smartmeter uses the home location_id directly.

0 commit comments

Comments
 (0)