44"""
55from __future__ import annotations
66
7- from plugwise .constants import ModelData
7+ from plugwise .constants import ANNA , SWITCH_GROUP_TYPES , DeviceData , ModelData
88from 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
0 commit comments