Skip to content

Commit c9459fb

Browse files
committed
Try 5
1 parent 177e16f commit c9459fb

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

plugwise/devices.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6+
from munch import Munch
67
from typing import Any
78

89
from .constants import ZONE_THERMOSTATS
@@ -70,6 +71,8 @@ class Gateway(DeviceBase):
7071
def __init__(self) -> None:
7172
"""Init Gateway class and inherited functions."""
7273
super().__init__()
74+
self.binary_sensors = GatewayBinarySensors()
75+
self.sensors = Weather()
7376

7477
def update_from_dict(self, data: dict[str, Any]) -> None:
7578
"""Update this Gateway object with data from a dictionary."""
@@ -263,6 +266,7 @@ class Zone(DeviceBase):
263266
def __init__(self) -> None:
264267
"""Init Zone class and inherited functions."""
265268
super().__init__()
269+
self.sensors = ZoneSensors()
266270

267271
def update_from_dict(self, data: dict[str, Any]) -> None:
268272
"""Update this climate Zone object with data from a dictionary."""
@@ -324,6 +328,8 @@ class Thermostat(DeviceBase):
324328
def __init__(self) -> None:
325329
"""Init Thermostat class and inherited functions."""
326330
super().__init__()
331+
self.binary_sensors = WirelessThermostatBinarySensors()
332+
self.sensors = ThermostatSensors()
327333

328334
def update_from_dict(self, data: dict[str, Any]) -> None:
329335
"""Update this Thermostat object with data from a dictionary."""
@@ -446,6 +452,9 @@ class ClimateDevice(DeviceBase):
446452
def __init__(self) -> None:
447453
"""Init ClimateDevice class and inherited functions."""
448454
super().__init__()
455+
self.binary_sensors = ClimateDeviceBinarySensors()
456+
self.sensors = ClimateDeviceSensors()
457+
self.switches = ClimateDeviceSwitches()
449458

450459
def update_from_dict(self, data: dict[str, Any]) -> None:
451460
"""Update this ClimateDevice object with data from a dictionary."""
@@ -548,6 +557,8 @@ class Plug(DeviceBase):
548557
def __init__(self) -> None:
549558
"""Init Plug class and inherited functions."""
550559
super().__init__()
560+
self.sensors = PlugSensors()
561+
self. switches = PlugSwitches()
551562

552563
def update_from_dict(self, data: dict[str, Any]) -> None:
553564
"""Update this Plug object with data from a dictionary."""
@@ -647,49 +658,74 @@ class PlugwiseData:
647658
plugs: list[Plug] | None = None
648659
p1_dsmr: SmartEnergyMeter | None = None
649660

650-
def __init__(self, smile) -> None:
661+
def __init__(self, data: Any) -> None:
651662
"""Initialize PlugwiseData class."""
652663
self.climate_device = None
653-
self.zones = None
654-
self.thermostats = None
655-
self.plugs = None
664+
self.gateway = None
656665
self.p1_dsmr = None
657-
self.smile = smile
666+
self.plugs = None
667+
self.thermostats = None
668+
self.zones = None
669+
670+
for device_id, device in data.items():
671+
self.gateway = Gateway()
672+
if device["dev_class"] == "gateway":
673+
self.gateway.update_from_dict(device)
658674

659-
if self.smile.type == "Adam":
660675
self.climate_device = ClimateDevice()
676+
if device["dev_class"] == "heater_central":
677+
self.climate_device.update_from_dict(device)
678+
661679
self.zones = list[Zone()]
680+
if device["dev_class"] == "climate":
681+
for zone in self.zones:
682+
zone.update_from_dict(device)
683+
self.zones.append(zone)
684+
662685
self.thermostats = list[Thermostat()]
686+
if device["dev_class"] in ZONE_THERMOSTATS:
687+
for thermostat in self.thermostats:
688+
thermostat.update_from_dict(device)
689+
self.thermostats.append(thermostat)
690+
663691
self.plugs = list[Plug()]
664-
if self.smile.type == "Smile Anna":
665-
self.climate_device = ClimateDevice()
666-
if self.smile.type == "Smile Anna P1":
667-
self.climate_device = ClimateDevice()
668-
self.p1_dsmr = SmartEnergyMeter()
669-
if self.smile.type == "Smile P1":
692+
if device["dev_class"].endswith("_plug"):
693+
for plug in self.plugs:
694+
plug.update_from_dict(device)
695+
self.plugs.append(plug)
696+
670697
self.p1_dsmr = SmartEnergyMeter()
671-
if self.smile.type == "Stretch":
672-
self.plugs = list[Plug()]
698+
if device["dev_class"] == "smartmeter":
699+
self.p1_dsmr.update_from_dict(device)
673700

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

677704
for device_id, device in data.items():
678-
if device["device_class"] == "gateway":
705+
if device["dev_class"] == "gateway":
706+
self.gateway = Gateway()
679707
self.gateway.update_from_dict(device)
680-
if device["device_class"] == "heater_central":
708+
if device["dev_class"] == "heater_central":
709+
self.climate_device = ClimateDevice()
681710
self.climate_device.update_from_dict(device)
682-
if device["device_class"] == "climate":
711+
if device["dev_class"] == "climate":
712+
self.zones = list[Zone()]
683713
for zone in self.zones:
684714
if zone.location == device_id:
685715
zone.update_from_dict(device)
686-
if device["device_class"] in ZONE_THERMOSTATS:
716+
self.zones.append(zone)
717+
if device["dev_class"] in ZONE_THERMOSTATS:
718+
self.thermostats = list[Thermostat()]
687719
for thermostat in self.thermostats:
688720
if thermostat.location == device["location"]:
689721
thermostat.update_from_dict(device)
690-
if device["device_class"].endswith("_plug"):
722+
self.thermostats.append(thermostat)
723+
if device["dev_class"].endswith("_plug"):
724+
self.plugs = list[Plug()]
691725
for plug in self.plugs:
692726
if plug.location == device["location"]:
693727
plug.update_from_dict(device)
694-
if device["device_class"] == "smartmeter":
728+
self.plugs.append(plug)
729+
if device["dev_class"] == "smartmeter":
730+
self.p1_dsmr = SmartEnergyMeter()
695731
self.p1_dsmr.update_from_dict(device)

plugwise/legacy/smile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
GwEntityData,
2424
ThermoLoc,
2525
)
26+
from plugwise.devices import PlugwiseData
2627
from plugwise.exceptions import ConnectionFailedError, DataMissingError, PlugwiseError
2728
from plugwise.legacy.data import SmileLegacyData
2829

@@ -52,6 +53,7 @@ def __init__(
5253
self._loc_data = _loc_data
5354
self._on_off_device = _on_off_device
5455
self._opentherm_device = _opentherm_device
56+
self._plugwise_data: PlugwiseData | None = None
5557
self._request = _request
5658
self._stretch_v2 = _stretch_v2
5759
self._target_smile = _target_smile
@@ -123,6 +125,7 @@ async def async_update(self) -> dict[str, GwEntityData]:
123125

124126
self._first_update = False
125127
self._previous_day_number = day_number
128+
self._plugwise_data = PlugwiseData(self.gw_entities)
126129
return self.gw_entities
127130

128131
########################################################################################################

plugwise/smile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
ThermoLoc,
3131
)
3232
from plugwise.data import SmileData
33+
from plugwise.devices import PlugwiseData
3334
from plugwise.exceptions import ConnectionFailedError, DataMissingError, PlugwiseError
3435

3536
from defusedxml import ElementTree as etree
@@ -84,6 +85,7 @@ def __init__(
8485
self._loc_data = _loc_data
8586
self._on_off_device = _on_off_device
8687
self._opentherm_device = _opentherm_device
88+
self._plugwise_data: PlugwiseData | None = None
8789
self._request = _request
8890
self._schedule_old_states = _schedule_old_states
8991
self.smile = smile
@@ -146,6 +148,7 @@ async def async_update(self) -> dict[str, GwEntityData]:
146148
except KeyError as err:
147149
raise DataMissingError("No Plugwise actual data received") from err
148150

151+
self._plugwise_data = PlugwiseData(self.gw_entities)
149152
return self.gw_entities
150153

151154
########################################################################################################

0 commit comments

Comments
 (0)