Skip to content

Commit 762d16f

Browse files
committed
Rename to _het_appliances(), _get_locations(), optimize _get_appliances()
1 parent 2a7f0e6 commit 762d16f

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

plugwise/helper.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,67 +93,66 @@ def item_count(self) -> int:
9393
"""Return the item-count."""
9494
return self._count
9595

96-
def _all_appliances(self) -> None:
96+
def _get_appliances(self) -> None:
9797
"""Collect all appliances with relevant info.
9898
9999
Also, collect the P1 smartmeter info from a location
100100
as this one is not available as an appliance.
101101
"""
102102
self._count = 0
103-
self._all_locations()
103+
self._get_locations()
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.module_id = None
114+
appl.firmware = None
115+
appl.hardware = None
116+
appl.mac = None
107117
appl.pwclass = appliance.find("type").text
108-
# Don't collect data for the OpenThermGateway appliance
109-
if appl.pwclass == "open_therm_gateway":
110-
continue
111-
112-
# Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739
113-
description = appliance.find("description").text
114-
if description is not None and (
115-
"ZigBee protocol" in description or "smart plug" in description
116-
):
117-
appl.pwclass = f"{appl.pwclass}_plug"
118+
appl.zigbee_mac = None
119+
appl.vendor_name = None
118120

119-
# Skip thermostats that have this key, should be an orphaned device (Core #81712)
120-
if (
121+
# Don't collect data for the OpenThermGateway appliance, skip thermostat(s)
122+
# without actuator_functionalities, should be an orphaned device(s) (Core #81712)
123+
if appl.pwclass == "open_therm_gateway" or (
121124
appl.pwclass == "thermostat"
122125
and appliance.find("actuator_functionalities/") is None
123126
):
124127
continue
125128

126-
appl.location = None
127129
if (appl_loc := appliance.find("location")) is not None:
128130
appl.location = appl_loc.attrib["id"]
129-
# Don't assign the _home_loc_id to thermostat-devices without a location,
130-
# they are not active
131+
# Set location to the _home_loc_id when the appliance-location is not found,
132+
# except for thermostat-devices without a location, they are not active
131133
elif appl.pwclass not in THERMOSTAT_CLASSES:
132134
appl.location = self._home_loc_id
133135

134136
# Don't show orphaned thermostat-types
135137
if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None:
136138
continue
137139

138-
appl.available = None
139-
appl.entity_id = appliance.attrib["id"]
140-
appl.name = appliance.find("name").text
141-
appl.model = None
142-
appl.model_id = None
143-
appl.firmware = None
144-
appl.hardware = None
145-
appl.mac = None
146-
appl.zigbee_mac = None
147-
appl.vendor_name = None
140+
# Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739
141+
description = appliance.find("description").text
142+
if description is not None and (
143+
"ZigBee protocol" in description or "smart plug" in description
144+
):
145+
appl.pwclass = f"{appl.pwclass}_plug"
148146

149147
# Collect appliance info, skip orphaned/removed devices
150148
if not (appl := self._appliance_info_finder(appl, appliance)):
151149
continue
152150

153151
self._create_gw_entities(appl)
154152

153+
# A smartmeter is not present as an appliance, add it specifically
155154
if self.smile.type == "power" or self.smile.anna_p1:
156-
self._get_p1_smartmeter_info()
155+
self._add_p1_smartmeter_info()
157156

158157
# Sort the gw_entities
159158
self._reorder_devices()

0 commit comments

Comments
 (0)