Skip to content

Commit 1531a6c

Browse files
committed
Add support for Groups
1 parent abf63f2 commit 1531a6c

File tree

1 file changed

+77
-15
lines changed

1 file changed

+77
-15
lines changed

plugwise/models.py

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,58 @@ def update_from_dict(self, data: dict[str, Any]) -> None:
507507
self.dhw_cm_switch = process_dict(data, "switches", "dhw_cm_switch")
508508

509509

510+
@dataclass(kw_only=True)
511+
class Group(DeviceBase):
512+
"""Group class covering switch-groups, pump-groups, for Adam and Stretch."""
513+
514+
sensors: GroupSensors
515+
switches: GroupSwitch
516+
517+
def __init__(self) -> None:
518+
"""Init Group class and inherited functions."""
519+
super().__init__()
520+
self.sensors = GroupSensors()
521+
self.switches = GroupSwitch()
522+
523+
def update_from_dict(self, data: dict[str, Any]) -> None:
524+
"""Update this Group object with data from a dictionary."""
525+
super().update_from_dict(data)
526+
self.sensors.update_from_dict(data)
527+
self.switches.update_from_dict(data)
528+
529+
530+
@dataclass(kw_only=True)
531+
class GroupSensors:
532+
"""Group sensors class."""
533+
534+
electricity_consumed: float | None = None
535+
electricity_produced: float | None = None
536+
temperature: float | None = None
537+
538+
def update_from_dict(self, data: dict[str, Any]) -> None:
539+
"""Update this GroupSensors object with data from a dictionary."""
540+
self.electricity_consumed = process_dict(
541+
data, "sensors", "electricity_consumed"
542+
)
543+
self.electricity_produced = process_dict(
544+
data, "sensors", "electricity_produced"
545+
)
546+
self.temperature = process_dict(data, "sensors", "temperature")
547+
548+
549+
@dataclass(kw_only=True)
550+
class GroupSwitch:
551+
"""Group switch class."""
552+
553+
lock: bool | None = None
554+
relay: bool | None = None
555+
556+
def update_from_dict(self, data: dict[str, Any]) -> None:
557+
"""Update this GroupSwitch object with data from a dictionary."""
558+
self.lock = process_dict(data, "switches", "lock")
559+
self.relay = process_dict(data, "switches", "relay")
560+
561+
510562
@dataclass(kw_only=True)
511563
class Plug(DeviceBase):
512564
"""Plug data class covering Plugwise Adam/Stretch and Aqara Plugs, and generic ZigBee type Switches."""
@@ -574,6 +626,7 @@ class PlugwiseData:
574626
- Gateway Adam
575627
- Climate device: OnOff or Opentherm
576628
- Zones (1 to many) with thermostatic and energy sensors summary, with thermostat setpoint- and mode-, preset- & schedule-setter
629+
- Groups - switching type
577630
- Single devices (appliances) assigned to a Zone, or not
578631
- Anna (wired thermostat)
579632
- Emma Pro wired (wired thermostat)
@@ -603,43 +656,40 @@ class PlugwiseData:
603656
604657
- Gateway Stretch (legacy)
605658
- Single devices (Zigbee)
659+
- Groups: switching and reporting types
606660
- ??
607661
"""
608662

609663
gateway: Gateway = Gateway()
610664
climate_device: ClimateDevice | None
611-
zones: list[Zone] | None
612-
thermostats: list[Thermostat] | None
665+
groups: list[Group] | None
613666
plugs: list[Plug] | None
614667
p1_dsmr: SmartEnergyMeter | None
668+
thermostats: list[Thermostat] | None
669+
zones: list[Zone] | None
615670

616671
def __init__(self, data: Any) -> None:
617672
"""Initialize PlugwiseData class."""
618673
self.climate_device = None
619-
self.p1_dsmr = None
674+
self.groups = None
620675
self.plugs = None
676+
self.p1_dsmr = None
621677
self.thermostats = None
622678
self.zones = None
623679

624680
for _, device in data.items():
625681
if device["dev_class"] == "gateway":
626682
self.gateway.update_from_dict(device)
683+
if device["dev_class"] in ("pumping", "report", "switching"):
684+
if self.groups is None:
685+
self.groups = []
686+
group = Group()
687+
group.update_from_dict(device)
688+
self.groups.append(group)
627689
if device["dev_class"] == "heater_central":
628690
if self.climate_device is None:
629691
self.climate_device = ClimateDevice()
630692
self.climate_device.update_from_dict(device)
631-
if device["dev_class"] == "climate":
632-
if self.zones is None:
633-
self.zones = []
634-
zone = Zone()
635-
zone.update_from_dict(device)
636-
self.zones.append(zone)
637-
if device["dev_class"] in ZONE_THERMOSTATS:
638-
if self.thermostats is None:
639-
self.thermostats = []
640-
thermostat = Thermostat()
641-
thermostat.update_from_dict(device)
642-
self.thermostats.append(thermostat)
643693
if device["dev_class"].endswith("_plug"):
644694
if self.plugs is None:
645695
self.plugs = []
@@ -650,6 +700,18 @@ def __init__(self, data: Any) -> None:
650700
if self.p1_dsmr is None:
651701
self.p1_dsmr = SmartEnergyMeter()
652702
self.p1_dsmr.update_from_dict(device)
703+
if device["dev_class"] in ZONE_THERMOSTATS:
704+
if self.thermostats is None:
705+
self.thermostats = []
706+
thermostat = Thermostat()
707+
thermostat.update_from_dict(device)
708+
self.thermostats.append(thermostat)
709+
if device["dev_class"] == "climate":
710+
if self.zones is None:
711+
self.zones = []
712+
zone = Zone()
713+
zone.update_from_dict(device)
714+
self.zones.append(zone)
653715

654716
def update_from_dict(self, data: dict[str, Any]) -> None:
655717
"""Update the status object with data received from the Plugwise API."""

0 commit comments

Comments
 (0)