Skip to content

Commit 23968c2

Browse files
committed
Reworking
1 parent f1ee968 commit 23968c2

File tree

7 files changed

+101
-96
lines changed

7 files changed

+101
-96
lines changed

fixtures/adam_plus_anna_new/all_data.json

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"binary_sensors": {
4343
"low_battery": false
4444
},
45-
"dev_class": "thermo_sensor",
45+
"dev_class": "thermostatic_radiator_valve",
4646
"firmware": "2020-11-04T01:00:00+01:00",
4747
"hardware": "1",
4848
"location": "f871b8c4d63549319221e294e4f88074",
@@ -145,39 +145,15 @@
145145
"zigbee_mac_address": "000D6F000D13CB6F"
146146
},
147147
"ad4838d7d35c4d6ea796ee12ae5aedf8": {
148-
"active_preset": "home",
149-
"available_schedules": [
150-
"Badkamer",
151-
"Test",
152-
"Vakantie",
153-
"Weekschema",
154-
"off"
155-
],
156-
"climate_mode": "auto",
157-
"control_state": "heating",
158148
"dev_class": "thermostat",
159149
"location": "f2bf9048bef64cc5b6d5110154e33c81",
160150
"model": "ThermoTouch",
161151
"model_id": "143.1",
162152
"name": "Anna",
163-
"preset_modes": [
164-
"no_frost",
165-
"asleep",
166-
"vacation",
167-
"home",
168-
"away"
169-
],
170-
"select_schedule": "Weekschema",
171153
"sensors": {
172154
"setpoint": 18.5,
173155
"temperature": 18.4
174156
},
175-
"thermostat": {
176-
"lower_bound": 1.0,
177-
"resolution": 0.01,
178-
"setpoint": 18.5,
179-
"upper_bound": 35.0
180-
},
181157
"vendor": "Plugwise"
182158
},
183159
"da224107914542988a88561b4452b0f6": {
@@ -212,35 +188,17 @@
212188
"zigbee_mac_address": "000D6F000D5A168D"
213189
},
214190
"e2f4322d57924fa090fbbc48b3a140dc": {
215-
"active_preset": "home",
216191
"available": true,
217-
"available_schedules": [
218-
"Badkamer",
219-
"Test",
220-
"Vakantie",
221-
"Weekschema",
222-
"off"
223-
],
224192
"binary_sensors": {
225193
"low_battery": true
226194
},
227-
"climate_mode": "auto",
228-
"control_state": "preheating",
229195
"dev_class": "zone_thermostat",
230196
"firmware": "2016-10-10T02:00:00+02:00",
231197
"hardware": "255",
232198
"location": "f871b8c4d63549319221e294e4f88074",
233199
"model": "Lisa",
234200
"model_id": "158-01",
235201
"name": "Lisa Badkamer",
236-
"preset_modes": [
237-
"no_frost",
238-
"asleep",
239-
"vacation",
240-
"home",
241-
"away"
242-
],
243-
"select_schedule": "Badkamer",
244202
"sensors": {
245203
"battery": 14,
246204
"setpoint": 18.0,
@@ -252,12 +210,6 @@
252210
"setpoint": 0.0,
253211
"upper_bound": 2.0
254212
},
255-
"thermostat": {
256-
"lower_bound": 0.0,
257-
"resolution": 0.01,
258-
"setpoint": 18.0,
259-
"upper_bound": 99.9
260-
},
261213
"vendor": "Plugwise",
262214
"zigbee_mac_address": "000D6F000C869B61"
263215
},
@@ -278,7 +230,7 @@
278230
"cooling_present": false,
279231
"gateway_id": "da224107914542988a88561b4452b0f6",
280232
"heater_id": "056ee145a816487eaa69243c3280f8bf",
281-
"item_count": 165,
233+
"item_count": 150,
282234
"notifications": {},
283235
"reboot": true,
284236
"smile_name": "Adam"

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def get_all_devices(self) -> None:
308308

309309
async def async_update(self) -> PlugwiseData:
310310
"""Perform an incremental update for updating the various device states."""
311-
data = PlugwiseData({}, {})
311+
data = PlugwiseData({}, {}, {})
312312
try:
313313
data = await self._smile_api.async_update()
314314
self.gateway_id = data.gateway["gateway_id"]

plugwise/constants.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@
144144
"relay": UOM(NONE),
145145
}
146146

147+
# Climate related measurements
148+
CLIMATE_MEASUREMENTS: Final[dict[str, DATA | UOM]] = {
149+
"temperature": UOM(TEMP_CELSIUS), # HA Core thermostat current_temperature
150+
}
151+
147152
# Heater Central related measurements
148153
HEATER_CENTRAL_MEASUREMENTS: Final[dict[str, DATA | UOM]] = {
149154
"boiler_state": DATA(
@@ -492,7 +497,7 @@ class ThermoLoc(TypedDict, total=False):
492497
"""Thermo Location class."""
493498

494499
name: str
495-
primary: str | None
500+
primary: set[str]
496501
primary_prio: int
497502
secondary: set[str]
498503

@@ -508,6 +513,25 @@ class ActuatorData(TypedDict, total=False):
508513
upper_bound: float
509514

510515

516+
class ClimateData(TypedDict, total=False):
517+
"""The Climate Data class, covering the collected and ordered output-data per location."""
518+
519+
dev_class: str
520+
name: str
521+
members: dict[str, str] # TODO complete
522+
climate_mode: str
523+
# Extra for Adam Master Thermostats
524+
control_state: str | bool
525+
# Presets:
526+
active_preset: str | None
527+
preset_modes: list[str] | None
528+
# Schedules:
529+
available_schedules: list[str]
530+
select_schedule: str
531+
532+
thermostat: ActuatorData
533+
534+
511535
class DeviceData(TypedDict, total=False):
512536
"""The Device Data class, covering the collected and ordered output-data per device."""
513537

@@ -544,32 +568,19 @@ class DeviceData(TypedDict, total=False):
544568
select_gateway_mode: str
545569
select_regulation_mode: str
546570

547-
# Master Thermostats
548-
# Presets:
549-
active_preset: str | None
550-
preset_modes: list[str] | None
551-
# Schedules:
552-
available_schedules: list[str]
553-
last_used: str | None
554-
select_schedule: str
555-
556-
climate_mode: str
557-
# Extra for Adam Master Thermostats
558-
control_state: str | bool
559-
560571
# Dict-types
561572
binary_sensors: SmileBinarySensors
562573
max_dhw_temperature: ActuatorData
563574
maximum_boiler_temperature: ActuatorData
564575
sensors: SmileSensors
565576
switches: SmileSwitches
566577
temperature_offset: ActuatorData
567-
thermostat: ActuatorData
568578

569579

570580
@dataclass
571581
class PlugwiseData:
572582
"""Plugwise data provided as output."""
573583

574584
gateway: GatewayData
585+
climates: dict[str, ClimateData]
575586
devices: dict[str, DeviceData]

plugwise/data.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from plugwise.constants import (
1010
ADAM,
1111
ANNA,
12+
LOGGER,
1213
MAX_SETPOINT,
1314
MIN_SETPOINT,
1415
NONE,
@@ -35,6 +36,7 @@ def _all_device_data(self) -> None:
3536
Collect data for each device and add to self.gw_data and self.gw_devices.
3637
"""
3738
self._update_gw_devices()
39+
self._update_climates()
3840
self.gw_data.update(
3941
{
4042
"gateway_id": self.gateway_id,
@@ -49,6 +51,15 @@ def _all_device_data(self) -> None:
4951
{"heater_id": self._heater_id, "cooling_present": self._cooling_present}
5052
)
5153

54+
def _update_climates(self) -> None:
55+
"""Helper-function for _all_device_data() and async_update().
56+
57+
Collect data for each climate-location and add to self.climate_data.
58+
"""
59+
for location_id, climate in self.climate_data.items():
60+
data = self._get_location_data(location_id)
61+
climate.update(data)
62+
5263
def _update_gw_devices(self) -> None:
5364
"""Helper-function for _all_device_data() and async_update().
5465
@@ -140,10 +151,27 @@ def _update_for_cooling(self, device: DeviceData) -> None:
140151
sensors["setpoint_high"] = temp_dict["setpoint_high"]
141152
self._count += 2
142153

143-
def _get_device_data(self, dev_id: str) -> DeviceData:
154+
155+
def _get_location_data(self, loc_id: str) -> DeviceData:
144156
"""Helper-function for _all_device_data() and async_update().
145157
146-
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
158+
Provide device-data, based on Location ID (= loc_id).
159+
"""
160+
climate = self.climate_data[loc_id]
161+
data = self._get_climate_data(loc_id)
162+
if ctrl_state := self._control_state(loc_id):
163+
data["control_state"] = ctrl_state
164+
self._count += 1
165+
166+
# Thermostat data (presets, temperatures etc)
167+
self._device_data_climate(loc_id, climate, data)
168+
169+
return data
170+
171+
def _get_device_data(self, dev_id: str) -> DeviceData:
172+
"""Helper-function for _update_gw_devices() and async_update().
173+
174+
Provide device-data, based on appliance_id ()= dev_id).
147175
"""
148176
device = self.gw_devices[dev_id]
149177
data = self._get_measurement_data(dev_id)
@@ -162,13 +190,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
162190
# Switching groups data
163191
self._device_data_switching_group(device, data)
164192
# Adam data
165-
self._device_data_adam(device, data)
166-
# Skip obtaining data for (Adam) secondary thermostats
167-
if device["dev_class"] not in ZONE_THERMOSTATS:
168-
return data
169-
170-
# Thermostat data (presets, temperatures etc)
171-
self._device_data_climate(device, data)
193+
self._device_data_adam(dev_id, device, data)
172194

173195
return data
174196

@@ -187,7 +209,7 @@ def _check_availability(
187209
if message in msg:
188210
data["available"] = False
189211

190-
def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
212+
def _device_data_adam(self, loc_id: str, device: DeviceData, data: DeviceData) -> None:
191213
"""Helper-function for _get_device_data().
192214
193215
Determine Adam heating-status for on-off heating via valves,
@@ -211,20 +233,12 @@ def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
211233
data["gateway_modes"] = self._gw_allowed_modes
212234
self._count += 1
213235

214-
# Control_state, only available for Adam primary thermostats
215-
if device["dev_class"] in ZONE_THERMOSTATS:
216-
loc_id = device["location"]
217-
if ctrl_state := self._control_state(loc_id):
218-
data["control_state"] = ctrl_state
219-
self._count += 1
220236

221-
def _device_data_climate(self, device: DeviceData, data: DeviceData) -> None:
237+
def _device_data_climate(self, loc_id: str, device: DeviceData, data: DeviceData) -> None:
222238
"""Helper-function for _get_device_data().
223239
224240
Determine climate-control device data.
225241
"""
226-
loc_id = device["location"]
227-
228242
# Presets
229243
data["preset_modes"] = None
230244
data["active_preset"] = None

0 commit comments

Comments
 (0)