|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | from dataclasses import dataclass |
| 6 | +from munch import Munch |
6 | 7 | from typing import Any |
7 | 8 |
|
8 | 9 | from .constants import ZONE_THERMOSTATS |
@@ -70,6 +71,8 @@ class Gateway(DeviceBase): |
70 | 71 | def __init__(self) -> None: |
71 | 72 | """Init Gateway class and inherited functions.""" |
72 | 73 | super().__init__() |
| 74 | + self.binary_sensors = GatewayBinarySensors() |
| 75 | + self.sensors = Weather() |
73 | 76 |
|
74 | 77 | def update_from_dict(self, data: dict[str, Any]) -> None: |
75 | 78 | """Update this Gateway object with data from a dictionary.""" |
@@ -263,6 +266,7 @@ class Zone(DeviceBase): |
263 | 266 | def __init__(self) -> None: |
264 | 267 | """Init Zone class and inherited functions.""" |
265 | 268 | super().__init__() |
| 269 | + self.sensors = ZoneSensors() |
266 | 270 |
|
267 | 271 | def update_from_dict(self, data: dict[str, Any]) -> None: |
268 | 272 | """Update this climate Zone object with data from a dictionary.""" |
@@ -324,6 +328,8 @@ class Thermostat(DeviceBase): |
324 | 328 | def __init__(self) -> None: |
325 | 329 | """Init Thermostat class and inherited functions.""" |
326 | 330 | super().__init__() |
| 331 | + self.binary_sensors = WirelessThermostatBinarySensors() |
| 332 | + self.sensors = ThermostatSensors() |
327 | 333 |
|
328 | 334 | def update_from_dict(self, data: dict[str, Any]) -> None: |
329 | 335 | """Update this Thermostat object with data from a dictionary.""" |
@@ -446,6 +452,9 @@ class ClimateDevice(DeviceBase): |
446 | 452 | def __init__(self) -> None: |
447 | 453 | """Init ClimateDevice class and inherited functions.""" |
448 | 454 | super().__init__() |
| 455 | + self.binary_sensors = ClimateDeviceBinarySensors() |
| 456 | + self.sensors = ClimateDeviceSensors() |
| 457 | + self.switches = ClimateDeviceSwitches() |
449 | 458 |
|
450 | 459 | def update_from_dict(self, data: dict[str, Any]) -> None: |
451 | 460 | """Update this ClimateDevice object with data from a dictionary.""" |
@@ -548,6 +557,8 @@ class Plug(DeviceBase): |
548 | 557 | def __init__(self) -> None: |
549 | 558 | """Init Plug class and inherited functions.""" |
550 | 559 | super().__init__() |
| 560 | + self.sensors = PlugSensors() |
| 561 | + self. switches = PlugSwitches() |
551 | 562 |
|
552 | 563 | def update_from_dict(self, data: dict[str, Any]) -> None: |
553 | 564 | """Update this Plug object with data from a dictionary.""" |
@@ -647,49 +658,74 @@ class PlugwiseData: |
647 | 658 | plugs: list[Plug] | None = None |
648 | 659 | p1_dsmr: SmartEnergyMeter | None = None |
649 | 660 |
|
650 | | - def __init__(self, smile) -> None: |
| 661 | + def __init__(self, data: Any) -> None: |
651 | 662 | """Initialize PlugwiseData class.""" |
652 | 663 | self.climate_device = None |
653 | | - self.zones = None |
654 | | - self.thermostats = None |
655 | | - self.plugs = None |
| 664 | + self.gateway = None |
656 | 665 | 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) |
658 | 674 |
|
659 | | - if self.smile.type == "Adam": |
660 | 675 | self.climate_device = ClimateDevice() |
| 676 | + if device["dev_class"] == "heater_central": |
| 677 | + self.climate_device.update_from_dict(device) |
| 678 | + |
661 | 679 | 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 | + |
662 | 685 | 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 | + |
663 | 691 | 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 | + |
670 | 697 | 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) |
673 | 700 |
|
674 | 701 | def update_from_dict(self, data: dict[str, Any]) -> None: |
675 | 702 | """Update the status object with data received from the Plugwise API.""" |
676 | 703 |
|
677 | 704 | for device_id, device in data.items(): |
678 | | - if device["device_class"] == "gateway": |
| 705 | + if device["dev_class"] == "gateway": |
| 706 | + self.gateway = Gateway() |
679 | 707 | 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() |
681 | 710 | self.climate_device.update_from_dict(device) |
682 | | - if device["device_class"] == "climate": |
| 711 | + if device["dev_class"] == "climate": |
| 712 | + self.zones = list[Zone()] |
683 | 713 | for zone in self.zones: |
684 | 714 | if zone.location == device_id: |
685 | 715 | 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()] |
687 | 719 | for thermostat in self.thermostats: |
688 | 720 | if thermostat.location == device["location"]: |
689 | 721 | 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()] |
691 | 725 | for plug in self.plugs: |
692 | 726 | if plug.location == device["location"]: |
693 | 727 | 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() |
695 | 731 | self.p1_dsmr.update_from_dict(device) |
0 commit comments