Skip to content

Commit 5e9e8bb

Browse files
committed
Combine to DeviceZoneData
1 parent fe2b5ab commit 5e9e8bb

File tree

9 files changed

+67
-96
lines changed

9 files changed

+67
-96
lines changed

plugwise/common.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SPECIAL_PLUG_TYPES,
1212
SWITCH_GROUP_TYPES,
1313
ApplianceType,
14-
DeviceData,
14+
DeviceZoneData,
1515
ModelData,
1616
SensorType,
1717
)
@@ -40,7 +40,7 @@ def __init__(self) -> None:
4040
self._heater_id: str
4141
self._on_off_device: bool
4242
self._opentherm_device: bool
43-
self.gw_devices: dict[str, DeviceData]
43+
self.gw_devices: dict[str, DeviceZoneData]
4444
self.smile_name: str
4545
self.smile_type: str
4646

@@ -108,7 +108,7 @@ def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None)
108108

109109
return appl
110110

111-
def _collect_power_values(self, data: DeviceData, loc: Munch, tariff: str, legacy: bool = False) -> None:
111+
def _collect_power_values(self, data: DeviceZoneData, loc: Munch, tariff: str, legacy: bool = False) -> None:
112112
"""Something."""
113113
for loc.peak_select in ("nl_peak", "nl_offpeak"):
114114
loc.locator = (
@@ -160,8 +160,8 @@ def _power_data_energy_diff(
160160
measurement: str,
161161
net_string: SensorType,
162162
f_val: float | int,
163-
direct_data: DeviceData,
164-
) -> DeviceData:
163+
direct_data: DeviceZoneData,
164+
) -> DeviceZoneData:
165165
"""Calculate differential energy."""
166166
if (
167167
"electricity" in measurement
@@ -208,7 +208,7 @@ def _create_gw_devices(self, appl: Munch) -> None:
208208
self._count += 1
209209

210210
def _device_data_switching_group(
211-
self, device: DeviceData, data: DeviceData
211+
self, device: DeviceZoneData, data: DeviceZoneData
212212
) -> None:
213213
"""Helper-function for _get_device_data().
214214
@@ -222,12 +222,12 @@ def _device_data_switching_group(
222222
data["switches"]["relay"] = counter != 0
223223
self._count += 1
224224

225-
def _get_group_switches(self) -> dict[str, DeviceData]:
225+
def _get_group_switches(self) -> dict[str, DeviceZoneData]:
226226
"""Helper-function for smile.py: get_all_devices().
227227
228228
Collect switching- or pump-group info.
229229
"""
230-
switch_groups: dict[str, DeviceData] = {}
230+
switch_groups: dict[str, DeviceZoneData] = {}
231231
# P1 and Anna don't have switchgroups
232232
if self.smile_type == "power" or self.smile(ANNA):
233233
return switch_groups
@@ -258,7 +258,7 @@ def _get_group_switches(self) -> dict[str, DeviceData]:
258258

259259
return switch_groups
260260

261-
def _get_lock_state(self, xml: etree, data: DeviceData, stretch_v2: bool = False) -> None:
261+
def _get_lock_state(self, xml: etree, data: DeviceZoneData, stretch_v2: bool = False) -> None:
262262
"""Helper-function for _get_measurement_data().
263263
264264
Adam & Stretches: obtain the relay-switch lock state.

plugwise/constants.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -516,35 +516,11 @@ class ActuatorData(TypedDict, total=False):
516516
upper_bound: float
517517

518518

519-
class MemberData:
520-
"""ZoneData Member data class."""
519+
class DeviceZoneData(TypedDict, total=False):
520+
"""The DeviceZone data class.
521521
522-
primary: list[str]
523-
secondary: list[str]
524-
525-
526-
class ZoneData(TypedDict, total=False):
527-
"""The Climate Data class, covering the collected and ordered output-data per location."""
528-
529-
dev_class: str
530-
name: str
531-
members: dict[str, list[str]]
532-
climate_mode: str
533-
# Extra for Adam Master Thermostats
534-
control_state: str | bool
535-
# Presets:
536-
active_preset: str | None
537-
preset_modes: list[str] | None
538-
# Schedules:
539-
available_schedules: list[str]
540-
select_schedule: str
541-
542-
sensors: SmileSensors
543-
thermostat: ActuatorData
544-
545-
546-
class DeviceData(TypedDict, total=False):
547-
"""The Device Data class, covering the collected and ordered output-data per device."""
522+
Covering the collected output-data per device or location.
523+
"""
548524

549525
# Appliance base data
550526
dev_class: str
@@ -579,7 +555,8 @@ class DeviceData(TypedDict, total=False):
579555
select_gateway_mode: str
580556
select_regulation_mode: str
581557

582-
# Single thermostat (Anna)
558+
# Thermostat-related
559+
thermostats: dict[str, list[str]]
583560
# Presets:
584561
active_preset: str | None
585562
preset_modes: list[str] | None
@@ -606,5 +583,5 @@ class PlugwiseData:
606583
"""Plugwise data provided as output."""
607584

608585
gateway: GatewayData
609-
devices: dict[str, DeviceData]
610-
zones: dict[str, ZoneData]
586+
devices: dict[str, DeviceZoneData]
587+
zones: dict[str, DeviceZoneData]

plugwise/data.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
NONE,
1515
OFF,
1616
ActuatorData,
17-
DeviceData,
18-
ZoneData,
17+
DeviceZoneData,
1918
)
2019
from plugwise.helper import SmileHelper
2120
from plugwise.util import remove_empty_platform_dicts
@@ -108,7 +107,7 @@ def _detect_low_batteries(self) -> list[str]:
108107
return mac_address_list
109108

110109
def _add_or_update_notifications(
111-
self, device_id: str, device: DeviceData, data: DeviceData
110+
self, device_id: str, device: DeviceZoneData, data: DeviceZoneData
112111
) -> None:
113112
"""Helper-function adding or updating the Plugwise notifications."""
114113
if (
@@ -123,7 +122,7 @@ def _add_or_update_notifications(
123122
data["binary_sensors"]["plugwise_notification"] = bool(self._notifications)
124123
self._count += 1
125124

126-
def _update_for_cooling(self, device: DeviceData) -> None:
125+
def _update_for_cooling(self, device: DeviceZoneData) -> None:
127126
"""Helper-function for adding/updating various cooling-related values."""
128127
# For Anna and heating + cooling, replace setpoint with setpoint_high/_low
129128
if (
@@ -152,7 +151,7 @@ def _update_for_cooling(self, device: DeviceData) -> None:
152151
self._count += 2 # add 4, remove 2
153152

154153

155-
def _get_location_data(self, loc_id: str) -> ZoneData:
154+
def _get_location_data(self, loc_id: str) -> DeviceZoneData:
156155
"""Helper-function for _all_device_data() and async_update().
157156
158157
Provide device-data, based on Location ID (= loc_id).
@@ -168,7 +167,7 @@ def _get_location_data(self, loc_id: str) -> ZoneData:
168167

169168
return data
170169

171-
def _get_device_data(self, dev_id: str) -> DeviceData:
170+
def _get_device_data(self, dev_id: str) -> DeviceZoneData:
172171
"""Helper-function for _update_gw_devices() and async_update().
173172
174173
Provide device-data, based on appliance_id ()= dev_id).
@@ -199,7 +198,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
199198
return data
200199

201200
def _check_availability(
202-
self, device: DeviceData, dev_class: str, data: DeviceData, message: str
201+
self, device: DeviceZoneData, dev_class: str, data: DeviceZoneData, message: str
203202
) -> None:
204203
"""Helper-function for _get_device_data().
205204
@@ -213,7 +212,7 @@ def _check_availability(
213212
if message in msg:
214213
data["available"] = False
215214

216-
def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
215+
def _device_data_adam(self, device: DeviceZoneData, data: DeviceZoneData) -> None:
217216
"""Helper-function for _get_device_data().
218217
219218
Determine Adam heating-status for on-off heating via valves,
@@ -241,8 +240,8 @@ def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
241240
def _device_data_climate(
242241
self,
243242
location_id: str,
244-
device: DeviceData | ZoneData,
245-
data: DeviceData | ZoneData
243+
device: DeviceZoneData,
244+
data: DeviceZoneData
246245
) -> None:
247246
"""Helper-function for _get_device_data().
248247
@@ -291,7 +290,7 @@ def check_reg_mode(self, mode: str) -> bool:
291290
)
292291

293292
def _get_schedule_states_with_off(
294-
self, location: str, schedules: list[str], selected: str, data: DeviceData | ZoneData
293+
self, location: str, schedules: list[str], selected: str, data: DeviceZoneData
295294
) -> None:
296295
"""Collect schedules with states for each thermostat.
297296

plugwise/helper.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
ActuatorData,
3737
ActuatorDataType,
3838
ActuatorType,
39-
DeviceData,
39+
DeviceZoneData,
4040
GatewayData,
4141
SensorType,
4242
ThermoLoc,
4343
ToggleNameType,
44-
ZoneData,
4544
)
4645
from plugwise.exceptions import (
4746
ConnectionFailedError,
@@ -251,7 +250,7 @@ def __init__(self) -> None:
251250

252251
self.gateway_id: str
253252
self.gw_data: GatewayData = {}
254-
self.gw_devices: dict[str, DeviceData] = {}
253+
self.gw_devices: dict[str, DeviceZoneData] = {}
255254
self.loc_data: dict[str, ThermoLoc]
256255
self.smile_fw_version: Version | None
257256
self.smile_hw_version: str | None
@@ -262,7 +261,7 @@ def __init__(self) -> None:
262261
self.smile_type: str
263262
self.smile_zigbee_mac_address: str | None
264263
self.therms_with_offset_func: list[str] = []
265-
self.zone_data: dict[str, ZoneData] = {}
264+
self.zone_data: dict[str, DeviceZoneData] = {}
266265
SmileCommon.__init__(self)
267266

268267
def _all_appliances(self) -> None:
@@ -483,12 +482,12 @@ def _get_appliances_with_offset_functionality(self) -> list[str]:
483482

484483
return therm_list
485484

486-
def _get_zone_data(self, loc_id: str) -> ZoneData:
485+
def _get_zone_data(self, loc_id: str) -> DeviceZoneData:
487486
"""Helper-function for smile.py: _get_device_data().
488487
489488
Collect the location-data based on location id.
490489
"""
491-
data: ZoneData = {"sensors": {}}
490+
data: DeviceZoneData = {"sensors": {}}
492491
zone = self.zone_data[loc_id]
493492
measurements = ZONE_MEASUREMENTS
494493
if (
@@ -499,12 +498,12 @@ def _get_zone_data(self, loc_id: str) -> ZoneData:
499498

500499
return data
501500

502-
def _get_measurement_data(self, dev_id: str) -> DeviceData:
501+
def _get_measurement_data(self, dev_id: str) -> DeviceZoneData:
503502
"""Helper-function for smile.py: _get_device_data().
504503
505504
Collect the appliance-data based on device id.
506505
"""
507-
data: DeviceData = {"binary_sensors": {}, "sensors": {}, "switches": {}}
506+
data: DeviceZoneData = {"binary_sensors": {}, "sensors": {}, "switches": {}}
508507
# Get P1 smartmeter data from LOCATIONS
509508
device = self.gw_devices[dev_id]
510509
# !! DON'T CHANGE below two if-lines, will break stuff !!
@@ -588,12 +587,12 @@ def _get_measurement_data(self, dev_id: str) -> DeviceData:
588587

589588
return data
590589

591-
def _power_data_from_location(self, loc_id: str) -> DeviceData:
590+
def _power_data_from_location(self, loc_id: str) -> DeviceZoneData:
592591
"""Helper-function for smile.py: _get_device_data().
593592
594593
Collect the power-data based on Location ID, from LOCATIONS.
595594
"""
596-
direct_data: DeviceData = {"sensors": {}}
595+
direct_data: DeviceZoneData = {"sensors": {}}
597596
loc = Munch()
598597
log_list: list[str] = ["point_log", "cumulative_log", "interval_log"]
599598
t_string = "tariff"
@@ -610,7 +609,7 @@ def _power_data_from_location(self, loc_id: str) -> DeviceData:
610609
def _appliance_measurements(
611610
self,
612611
appliance: etree,
613-
data: DeviceData,
612+
data: DeviceZoneData,
614613
measurements: dict[str, DATA | UOM],
615614
) -> None:
616615
"""Helper-function for _get_measurement_data() - collect appliance measurement data."""
@@ -648,7 +647,7 @@ def _appliance_measurements(
648647
self._count += len(data) - 3
649648

650649
def _get_toggle_state(
651-
self, xml: etree, toggle: str, name: ToggleNameType, data: DeviceData
650+
self, xml: etree, toggle: str, name: ToggleNameType, data: DeviceZoneData
652651
) -> None:
653652
"""Helper-function for _get_measurement_data().
654653
@@ -677,7 +676,7 @@ def _get_plugwise_notifications(self) -> None:
677676
)
678677

679678
def _get_actuator_functionalities(
680-
self, xml: etree, device: DeviceData, data: DeviceData
679+
self, xml: etree, device: DeviceZoneData, data: DeviceZoneData
681680
) -> None:
682681
"""Helper-function for _get_measurement_data()."""
683682
for item in ACTIVE_ACTUATORS:
@@ -732,7 +731,7 @@ def _get_actuator_functionalities(
732731
act_item = cast(ActuatorType, item)
733732
data[act_item] = temp_dict
734733

735-
def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None:
734+
def _get_regulation_mode(self, appliance: etree, data: DeviceZoneData) -> None:
736735
"""Helper-function for _get_measurement_data().
737736
738737
Collect the gateway regulation_mode.
@@ -743,7 +742,7 @@ def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None:
743742
self._count += 1
744743
self._cooling_enabled = data["select_regulation_mode"] == "cooling"
745744

746-
def _get_gateway_mode(self, appliance: etree, data: DeviceData) -> None:
745+
def _get_gateway_mode(self, appliance: etree, data: DeviceZoneData) -> None:
747746
"""Helper-function for _get_measurement_data().
748747
749748
Collect the gateway mode.
@@ -766,7 +765,7 @@ def _object_value(self, obj_id: str, measurement: str) -> float | int | None:
766765

767766
return val
768767

769-
def _process_c_heating_state(self, data: DeviceData) -> None:
768+
def _process_c_heating_state(self, data: DeviceZoneData) -> None:
770769
"""Helper-function for _get_measurement_data().
771770
772771
Process the central_heating_state value.
@@ -794,7 +793,7 @@ def _process_c_heating_state(self, data: DeviceData) -> None:
794793
if self._elga:
795794
data["binary_sensors"]["heating_state"] = data["c_heating_state"]
796795

797-
def _cleanup_data(self, data: DeviceData) -> None:
796+
def _cleanup_data(self, data: DeviceZoneData) -> None:
798797
"""Helper-function for _get_measurement_data().
799798
800799
Clean up the data dict.
@@ -842,7 +841,7 @@ def _scan_thermostats(self) -> None:
842841
loc_id: {
843842
"dev_class": "climate",
844843
"name": loc_data["name"],
845-
"members": {"primary": loc_data["primary"], "secondary": loc_data["secondary"]}
844+
"thermostats": {"primary": loc_data["primary"], "secondary": loc_data["secondary"]}
846845
}
847846
}
848847
)
@@ -869,7 +868,7 @@ def _rank_thermostat(
869868
thermo_matching: dict[str, int],
870869
loc_id: str,
871870
appliance_id: str,
872-
appliance_details: DeviceData,
871+
appliance_details: DeviceZoneData,
873872
) -> None:
874873
"""Helper-function for _scan_thermostats().
875874

plugwise/legacy/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Dict as class
88
# Version detection
9-
from plugwise.constants import NONE, OFF, DeviceData
9+
from plugwise.constants import NONE, OFF, DeviceZoneData
1010
from plugwise.legacy.helper import SmileLegacyHelper
1111
from plugwise.util import remove_empty_platform_dicts
1212

@@ -46,7 +46,7 @@ def _update_gw_devices(self) -> None:
4646
device.update(data)
4747
remove_empty_platform_dicts(device)
4848

49-
def _get_device_data(self, dev_id: str) -> DeviceData:
49+
def _get_device_data(self, dev_id: str) -> DeviceZoneData:
5050
"""Helper-function for _all_device_data() and async_update().
5151
5252
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
@@ -66,7 +66,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
6666

6767
return data
6868

69-
def _device_data_climate(self, device: DeviceData, data: DeviceData) -> None:
69+
def _device_data_climate(self, device: DeviceZoneData, data: DeviceZoneData) -> None:
7070
"""Helper-function for _get_device_data().
7171
7272
Determine climate-control device data.

0 commit comments

Comments
 (0)