Skip to content

Commit 3fe93d9

Browse files
committed
Remove switch and report groups
Use the HA Group helper to create a group of switches
1 parent 8182e8c commit 3fe93d9

File tree

6 files changed

+7
-90
lines changed

6 files changed

+7
-90
lines changed

plugwise/common.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from plugwise.constants import (
1111
ANNA,
12-
GROUP_TYPES,
1312
NONE,
1413
PRIORITY_DEVICE_CLASSES,
1514
SPECIAL_PLUG_TYPES,
@@ -175,23 +174,10 @@ def _reorder_devices(self) -> None:
175174
break
176175
self.gw_entities = {**reordered, **self.gw_entities}
177176

178-
def _entity_switching_group(self, entity: GwEntityData, data: GwEntityData) -> None:
179-
"""Helper-function for _get_device_zone_data().
180-
181-
Determine switching group device data.
182-
"""
183-
if entity["dev_class"] in SWITCH_GROUP_TYPES:
184-
counter = 0
185-
for member in entity["members"]:
186-
if self.gw_entities[member]["switches"].get("relay"):
187-
counter += 1
188-
data["switches"]["relay"] = counter != 0
189-
self._count += 1
190-
191177
def _get_groups(self) -> dict[str, GwEntityData]:
192178
"""Helper-function for smile.py: get_all_gateway_entities().
193179
194-
Collect switching-, pumping- or report-group info.
180+
Collect pumping-groups info.
195181
"""
196182
groups: dict[str, GwEntityData] = {}
197183
# P1 and Anna don't have groups
@@ -203,13 +189,16 @@ def _get_groups(self) -> dict[str, GwEntityData]:
203189
group_id = group.attrib["id"]
204190
group_name = group.find("name").text
205191
group_type = group.find("type").text
192+
if group_type != "pumping":
193+
continue
194+
206195
group_appliances = group.findall("appliances/appliance")
207196
for item in group_appliances:
208197
# Check if members are not orphaned - stretch
209198
if item.attrib["id"] in self.gw_entities:
210199
members.append(item.attrib["id"])
211200

212-
if group_type in GROUP_TYPES and members:
201+
if members:
213202
groups[group_id] = {
214203
"dev_class": group_type,
215204
"model": "Group",

plugwise/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@
304304
]
305305
BINARY_SENSORS: Final[tuple[str, ...]] = get_args(BinarySensorType)
306306

307-
GROUP_TYPES: Final[tuple[str, ...]] = ("pumping", "report", "switching")
308-
309307
SensorType = Literal[
310308
"battery",
311309
"cooling_activation_outdoor_temperature",

plugwise/data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ def _get_entity_data(self, entity_id: str) -> GwEntityData:
194194
self._check_availability(
195195
entity, "smartmeter", data, "P1 does not seem to be connected"
196196
)
197+
197198
# OpenTherm entity
198199
if entity["name"] != "OnOff":
199200
self._check_availability(
200201
entity, "heater_central", data, "no OpenTherm communication"
201202
)
202203

203-
# Switching groups data
204-
self._entity_switching_group(entity, data)
205204
# Adam data
206205
if self.check_name(ADAM):
207206
self._get_adam_data(entity, data)

plugwise/legacy/data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def _get_entity_data(self, entity_id: str) -> GwEntityData:
4040
entity = self.gw_entities[entity_id]
4141
data = self._get_measurement_data(entity_id)
4242

43-
# Switching groups data
44-
self._entity_switching_group(entity, data)
45-
4643
# Skip obtaining data when not a thermostat
4744
if entity["dev_class"] != "thermostat":
4845
return data

plugwise/legacy/smile.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ def get_all_gateway_entities(self) -> None:
7878
"""Collect the Plugwise gateway entities and their data and states from the received raw XML-data.
7979
8080
First, collect all the connected entities and their initial data.
81-
Collect and add switching- and/or pump-group entities.
8281
Finally, collect the data and states for each entity.
8382
"""
8483
self._all_appliances()
85-
if group_data := self._get_groups():
86-
self.gw_entities.update(group_data)
87-
8884
self._all_entity_data()
8985

9086
async def async_update(self) -> dict[str, GwEntityData]:
@@ -225,7 +221,6 @@ async def set_switch_state(
225221
"""Set the given state of the relevant switch.
226222
227223
For individual switches, sets the state directly.
228-
For group switches, sets the state for each member in the group separately.
229224
For switch-locks, sets the lock state using a different data format.
230225
Return the requested state when succesful, the current state otherwise.
231226
"""
@@ -261,13 +256,6 @@ async def set_switch_state(
261256
await self.call_request(APPLIANCES, method="post", data=data)
262257
return requested_state
263258

264-
# Handle group of switches
265-
data = f"<{switch.func_type}><state>{state}</state></{switch.func_type}>"
266-
if members is not None:
267-
return await self._set_groupswitch_member_state(
268-
appl_id, data, members, state, switch
269-
)
270-
271259
# Handle individual relay switches
272260
uri = f"{APPLIANCES};id={appl_id}/relay"
273261
if model == "relay" and self.gw_entities[appl_id]["switches"]["lock"]:
@@ -277,28 +265,6 @@ async def set_switch_state(
277265
await self.call_request(uri, method="put", data=data)
278266
return requested_state
279267

280-
async def _set_groupswitch_member_state(
281-
self, appl_id: str, data: str, members: list[str], state: str, switch: Munch
282-
) -> bool:
283-
"""Helper-function for set_switch_state().
284-
285-
Set the requested state of the relevant switch within a group of switches.
286-
Return the current group-state when none of the switches has changed its state, the requested state otherwise.
287-
"""
288-
current_state = self.gw_entities[appl_id]["switches"]["relay"]
289-
requested_state = state == STATE_ON
290-
switched = 0
291-
for member in members:
292-
if not self.gw_entities[member]["switches"]["lock"]:
293-
uri = f"{APPLIANCES};id={member}/relay"
294-
await self.call_request(uri, method="put", data=data)
295-
switched += 1
296-
297-
if switched > 0:
298-
return requested_state
299-
300-
return current_state # pragma: no cover
301-
302268
async def set_temperature(self, _: str, items: dict[str, float]) -> None:
303269
"""Set the given Temperature on the relevant Thermostat."""
304270
setpoint: float | None = None

plugwise/smile.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_all_gateway_entities(self) -> None:
104104
105105
First, collect all the connected entities and their initial data.
106106
If a thermostat-gateway, collect a list of thermostats with offset-capability.
107-
Collect and add switching- and/or pump-group entities.
107+
Collect and add pumping-group entities.
108108
Finally, collect the data and states for each entity.
109109
"""
110110
self._all_appliances()
@@ -399,7 +399,6 @@ async def set_switch_state(
399399
"""Set the given state of the relevant Switch.
400400
401401
For individual switches, sets the state directly.
402-
For group switches, sets the state for each member in the group separately.
403402
For switch-locks, sets the lock state using a different data format.
404403
Return the requested state when succesful, the current state otherwise.
405404
"""
@@ -418,11 +417,6 @@ async def set_switch_state(
418417
f"</{switch.func_type}>"
419418
)
420419

421-
if members is not None:
422-
return await self._set_groupswitch_member_state(
423-
appl_id, data, members, state, switch
424-
)
425-
426420
locator = f'appliance[@id="{appl_id}"]/{switch.actuator}/{switch.func_type}'
427421
found = self._domain_objects.findall(locator)
428422
for item in found:
@@ -445,32 +439,6 @@ async def set_switch_state(
445439
await self.call_request(uri, method="put", data=data)
446440
return requested_state
447441

448-
async def _set_groupswitch_member_state(
449-
self, appl_id: str, data: str, members: list[str], state: str, switch: Munch
450-
) -> bool:
451-
"""Helper-function for set_switch_state().
452-
453-
Set the requested state of the relevant switch within a group of switches.
454-
Return the current group-state when none of the switches has changed its state, the requested state otherwise.
455-
"""
456-
current_state = self.gw_entities[appl_id]["switches"]["relay"]
457-
requested_state = state == STATE_ON
458-
switched = 0
459-
for member in members:
460-
locator = f'appliance[@id="{member}"]/{switch.actuator}/{switch.func_type}'
461-
switch_id = self._domain_objects.find(locator).attrib["id"]
462-
uri = f"{APPLIANCES};id={member}/{switch.device};id={switch_id}"
463-
lock_blocked = self.gw_entities[member]["switches"].get("lock")
464-
# Assume Plugs under Plugwise control are not part of a group
465-
if lock_blocked is not None and not lock_blocked:
466-
await self.call_request(uri, method="put", data=data)
467-
switched += 1
468-
469-
if switched > 0:
470-
return requested_state
471-
472-
return current_state
473-
474442
async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
475443
"""Set the given Temperature on the relevant Thermostat."""
476444
setpoint: float | None = None

0 commit comments

Comments
 (0)