plugwise 0.36.2__py3-none-any.whl → 0.37.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ """Use of this source code is governed by the MIT license found in the LICENSE file.
2
+
3
+ Plugwise Smile protocol data-collection helpers for legacy devices.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ # Dict as class
8
+ # Version detection
9
+ from plugwise.constants import NONE, SWITCH_GROUP_TYPES, ZONE_THERMOSTATS, DeviceData
10
+ from plugwise.legacy.helper import SmileLegacyHelper
11
+ from plugwise.util import remove_empty_platform_dicts
12
+
13
+
14
+ class SmileLegacyData(SmileLegacyHelper):
15
+ """The Plugwise Smile main class."""
16
+
17
+ def __init__(self) -> None:
18
+ """Init."""
19
+ SmileLegacyHelper.__init__(self)
20
+
21
+ def _update_gw_devices(self) -> None:
22
+ """Helper-function for _all_device_data() and async_update().
23
+
24
+ Collect data for each device and add to self.gw_devices.
25
+ """
26
+ for device_id, device in self.gw_devices.items():
27
+ data = self._get_device_data(device_id)
28
+ self._add_or_update_notifications(device_id, device, data)
29
+ device.update(data)
30
+ remove_empty_platform_dicts(device)
31
+
32
+ def _add_or_update_notifications(
33
+ self, device_id: str, device: DeviceData, data: DeviceData
34
+ ) -> None:
35
+ """Helper-function adding or updating the Plugwise notifications."""
36
+ if (
37
+ device_id == self.gateway_id and self._is_thermostat
38
+ ) or (
39
+ "binary_sensors" in device
40
+ and "plugwise_notification" in device["binary_sensors"]
41
+ ):
42
+ data["binary_sensors"]["plugwise_notification"] = bool(self._notifications)
43
+ self._count += 1
44
+
45
+ def _all_device_data(self) -> None:
46
+ """Helper-function for get_all_devices().
47
+
48
+ Collect data for each device and add to self.gw_data and self.gw_devices.
49
+ """
50
+ self._update_gw_devices()
51
+ self.device_items = self._count
52
+
53
+ self.gw_data.update(
54
+ {
55
+ "gateway_id": self.gateway_id,
56
+ "item_count": self._count,
57
+ "notifications": self._notifications,
58
+ "smile_name": self.smile_name,
59
+ }
60
+ )
61
+ if self._is_thermostat:
62
+ self.gw_data.update(
63
+ {"heater_id": self._heater_id, "cooling_present": False}
64
+ )
65
+
66
+ def _device_data_switching_group(
67
+ self, device: DeviceData, data: DeviceData
68
+ ) -> None:
69
+ """Helper-function for _get_device_data().
70
+
71
+ Determine switching group device data.
72
+ """
73
+ if device["dev_class"] in SWITCH_GROUP_TYPES:
74
+ counter = 0
75
+ for member in device["members"]:
76
+ if self.gw_devices[member]["switches"].get("relay"):
77
+ counter += 1
78
+ data["switches"]["relay"] = counter != 0
79
+ self._count += 1
80
+
81
+ def _device_data_climate(self, device: DeviceData, data: DeviceData) -> None:
82
+ """Helper-function for _get_device_data().
83
+
84
+ Determine climate-control device data.
85
+ """
86
+ # Presets
87
+ data["preset_modes"] = None
88
+ data["active_preset"] = None
89
+ self._count += 2
90
+ if presets := self._presets():
91
+ data["preset_modes"] = list(presets)
92
+ data["active_preset"] = self._preset()
93
+
94
+ # Schedule
95
+ avail_schedules, sel_schedule = self._schedules()
96
+ data["available_schedules"] = avail_schedules
97
+ data["select_schedule"] = sel_schedule
98
+ self._count += 2
99
+
100
+ # Operation modes: auto, heat
101
+ data["mode"] = "auto"
102
+ self._count += 1
103
+ if sel_schedule == NONE:
104
+ data["mode"] = "heat"
105
+
106
+ def _get_device_data(self, dev_id: str) -> DeviceData:
107
+ """Helper-function for _all_device_data() and async_update().
108
+
109
+ Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
110
+ """
111
+ device = self.gw_devices[dev_id]
112
+ data = self._get_measurement_data(dev_id)
113
+
114
+ # Switching groups data
115
+ self._device_data_switching_group(device, data)
116
+
117
+ # Skip obtaining data for non master-thermostats
118
+ if device["dev_class"] not in ZONE_THERMOSTATS:
119
+ return data
120
+
121
+ # Thermostat data (presets, temperatures etc)
122
+ self._device_data_climate(device, data)
123
+
124
+ return data