Skip to content

Commit 4c64ca3

Browse files
committed
Move _get_lock_state() to common.py, make it a common function
1 parent c7dbf96 commit 4c64ca3

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

plugwise/common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from plugwise.constants import (
1010
ANNA,
11+
SPECIAL_PLUG_TYPES,
1112
SWITCH_GROUP_TYPES,
1213
ApplianceType,
1314
DeviceData,
@@ -157,6 +158,22 @@ def _get_group_switches(self) -> dict[str, DeviceData]:
157158

158159
return switch_groups
159160

161+
def _get_lock_state(self, xml: etree, data: DeviceData, stretch_v2: bool = False) -> None:
162+
"""Helper-function for _get_measurement_data().
163+
164+
Adam & Stretches: obtain the relay-switch lock state.
165+
"""
166+
actuator = "actuator_functionalities"
167+
func_type = "relay_functionality"
168+
if stretch_v2:
169+
actuator = "actuators"
170+
func_type = "relay"
171+
if xml.find("type").text not in SPECIAL_PLUG_TYPES:
172+
locator = f"./{actuator}/{func_type}/lock"
173+
if (found := xml.find(locator)) is not None:
174+
data["switches"]["lock"] = found.text == "true"
175+
self._count += 1
176+
160177
def _get_module_data(
161178
self,
162179
xml_1: etree,

plugwise/helper.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
OFF,
3232
P1_MEASUREMENTS,
3333
SENSORS,
34-
SPECIAL_PLUG_TYPES,
3534
SPECIALS,
3635
SWITCHES,
3736
TEMP_CELSIUS,
@@ -687,19 +686,6 @@ def _appliance_measurements(
687686
# Don't count the above top-level dicts, only the remaining single items
688687
self._count += len(data) - 3
689688

690-
def _get_lock_state(self, xml: etree, data: DeviceData) -> None:
691-
"""Helper-function for _get_measurement_data().
692-
693-
Adam & Stretches: obtain the relay-switch lock state.
694-
"""
695-
actuator = "actuator_functionalities"
696-
func_type = "relay_functionality"
697-
if xml.find("type").text not in SPECIAL_PLUG_TYPES:
698-
locator = f"./{actuator}/{func_type}/lock"
699-
if (found := xml.find(locator)) is not None:
700-
data["switches"]["lock"] = found.text == "true"
701-
self._count += 1
702-
703689
def _get_toggle_state(
704690
self, xml: etree, toggle: str, name: ToggleNameType, data: DeviceData
705691
) -> None:

plugwise/legacy/helper.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
OBSOLETE_MEASUREMENTS,
2727
P1_LEGACY_MEASUREMENTS,
2828
SENSORS,
29-
SPECIAL_PLUG_TYPES,
3029
SPECIALS,
3130
SWITCHES,
3231
TEMP_CELSIUS,
@@ -282,7 +281,7 @@ def _get_measurement_data(self, dev_id: str) -> DeviceData:
282281
appliance := self._appliances.find(f'./appliance[@id="{dev_id}"]')
283282
) is not None:
284283
self._appliance_measurements(appliance, data, measurements)
285-
self._get_lock_state(appliance, data)
284+
self._get_lock_state(appliance, data, self._stretch_v2)
286285

287286
if appliance.find("type").text in ACTUATOR_CLASSES:
288287
self._get_actuator_functionalities(appliance, device, data)
@@ -438,22 +437,6 @@ def _appliance_measurements(
438437
# Don't count the above top-level dicts, only the remaining single items
439438
self._count += len(data) - 3
440439

441-
def _get_lock_state(self, xml: etree, data: DeviceData) -> None:
442-
"""Helper-function for _get_measurement_data().
443-
444-
Adam & Stretches: obtain the relay-switch lock state.
445-
"""
446-
actuator = "actuator_functionalities"
447-
func_type = "relay_functionality"
448-
if self._stretch_v2:
449-
actuator = "actuators"
450-
func_type = "relay"
451-
if xml.find("type").text not in SPECIAL_PLUG_TYPES:
452-
locator = f"./{actuator}/{func_type}/lock"
453-
if (found := xml.find(locator)) is not None:
454-
data["switches"]["lock"] = found.text == "true"
455-
self._count += 1
456-
457440
def _get_actuator_functionalities(
458441
self, xml: etree, device: DeviceData, data: DeviceData
459442
) -> None:

0 commit comments

Comments
 (0)