Skip to content

Commit 60029a6

Browse files
committed
Move and combine _get_group_switches()
1 parent 7fd7481 commit 60029a6

File tree

3 files changed

+39
-76
lines changed

3 files changed

+39
-76
lines changed

plugwise/common.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
from __future__ import annotations
66

7-
from plugwise.constants import ModelData
7+
from plugwise.constants import ANNA, SWITCH_GROUP_TYPES, DeviceData, ModelData
88
from plugwise.util import (
99
check_heater_central,
1010
check_model,
@@ -22,12 +22,15 @@ class SmileCommon:
2222
def __init__(self) -> None:
2323
"""Init."""
2424
self._appliances: etree
25+
self._count: int
2526
self._domain_objects: etree
2627
self._cooling_present: bool
2728
self._heater_id: str
2829
self._on_off_device: bool
2930
self._opentherm_device: bool
31+
self.gw_devices: dict[str, DeviceData]
3032
self.smile_name: str
33+
self.smile_type: str
3134

3235
def smile(self, name: str) -> bool:
3336
"""Helper-function checking the smile-name."""
@@ -149,3 +152,38 @@ def _get_zigbee_data(self, module: etree, model_data: ModelData, legacy: bool) -
149152
model_data["zigbee_mac_address"] = zb_node.find("mac_address").text
150153
model_data["reachable"] = zb_node.find("reachable").text == "true"
151154

155+
def _get_group_switches(self) -> dict[str, DeviceData]:
156+
"""Helper-function for smile.py: get_all_devices().
157+
158+
Collect switching- or pump-group info.
159+
"""
160+
switch_groups: dict[str, DeviceData] = {}
161+
# P1 and Anna don't have switchgroups
162+
if self.smile_type == "power" or self.smile(ANNA):
163+
return switch_groups
164+
165+
for group in self._domain_objects.findall("./group"):
166+
members: list[str] = []
167+
group_id = group.attrib["id"]
168+
group_name = group.find("name").text
169+
group_type = group.find("type").text
170+
group_appliances = group.findall("appliances/appliance")
171+
for item in group_appliances:
172+
# Check if members are not orphaned - stretch
173+
if item.attrib["id"] in self.gw_devices:
174+
members.append(item.attrib["id"])
175+
176+
if group_type in SWITCH_GROUP_TYPES and members:
177+
switch_groups.update(
178+
{
179+
group_id: {
180+
"dev_class": group_type,
181+
"model": "Switchgroup",
182+
"name": group_name,
183+
"members": members,
184+
},
185+
},
186+
)
187+
self._count += 4
188+
189+
return switch_groups

plugwise/helper.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
SENSORS,
3434
SPECIAL_PLUG_TYPES,
3535
SPECIALS,
36-
SWITCH_GROUP_TYPES,
3736
SWITCHES,
3837
TEMP_CELSIUS,
3938
THERMOSTAT_CLASSES,
@@ -946,42 +945,6 @@ def _thermostat_uri(self, loc_id: str) -> str:
946945

947946
return f"{LOCATIONS};id={loc_id}/thermostat;id={thermostat_functionality_id}"
948947

949-
def _get_group_switches(self) -> dict[str, DeviceData]:
950-
"""Helper-function for smile.py: get_all_devices().
951-
952-
Collect switching- or pump-group info.
953-
"""
954-
switch_groups: dict[str, DeviceData] = {}
955-
# P1 and Anna don't have switchgroups
956-
if self.smile_type == "power" or self.smile(ANNA):
957-
return switch_groups
958-
959-
for group in self._domain_objects.findall("./group"):
960-
members: list[str] = []
961-
group_id = group.attrib["id"]
962-
group_name = group.find("name").text
963-
group_type = group.find("type").text
964-
group_appliances = group.findall("appliances/appliance")
965-
# Check if members are not orphaned
966-
for item in group_appliances:
967-
if item.attrib["id"] in self.gw_devices:
968-
members.append(item.attrib["id"])
969-
970-
if group_type in SWITCH_GROUP_TYPES and members:
971-
switch_groups.update(
972-
{
973-
group_id: {
974-
"dev_class": group_type,
975-
"model": "Switchgroup",
976-
"name": group_name,
977-
"members": members,
978-
},
979-
},
980-
)
981-
self._count += 4
982-
983-
return switch_groups
984-
985948
def _heating_valves(self) -> int | bool:
986949
"""Helper-function for smile.py: _device_data_adam().
987950

plugwise/legacy/helper.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from plugwise.constants import (
1212
ACTIVE_ACTUATORS,
1313
ACTUATOR_CLASSES,
14-
ANNA,
1514
APPLIANCES,
1615
ATTR_NAME,
1716
ATTR_UNIT_OF_MEASUREMENT,
@@ -29,7 +28,6 @@
2928
SENSORS,
3029
SPECIAL_PLUG_TYPES,
3130
SPECIALS,
32-
SWITCH_GROUP_TYPES,
3331
SWITCHES,
3432
TEMP_CELSIUS,
3533
THERMOSTAT_CLASSES,
@@ -455,42 +453,6 @@ def _thermostat_uri(self) -> str:
455453

456454
return f"{APPLIANCES};id={appliance_id}/thermostat"
457455

458-
def _get_group_switches(self) -> dict[str, DeviceData]:
459-
"""Helper-function for smile.py: get_all_devices().
460-
461-
Collect switching- or pump-group info.
462-
"""
463-
switch_groups: dict[str, DeviceData] = {}
464-
# P1 and Anna don't have switchgroups
465-
if self.smile_type == "power" or self.smile(ANNA):
466-
return switch_groups
467-
468-
for group in self._domain_objects.findall("./group"):
469-
members: list[str] = []
470-
group_id = group.attrib["id"]
471-
group_name = group.find("name").text
472-
group_type = group.find("type").text
473-
group_appliances = group.findall("appliances/appliance")
474-
for item in group_appliances:
475-
# Check if members are not orphaned - stretch
476-
if item.attrib["id"] in self.gw_devices:
477-
members.append(item.attrib["id"])
478-
479-
if group_type in SWITCH_GROUP_TYPES and members:
480-
switch_groups.update(
481-
{
482-
group_id: {
483-
"dev_class": group_type,
484-
"model": "Switchgroup",
485-
"name": group_name,
486-
"members": members,
487-
},
488-
},
489-
)
490-
self._count += 4
491-
492-
return switch_groups
493-
494456
def power_data_energy_diff(
495457
self,
496458
measurement: str,

0 commit comments

Comments
 (0)