33"""
44from __future__ import annotations
55
6- from typing import Any
7-
86import aiohttp
97from defusedxml import ElementTree as etree
108
3129 STATUS ,
3230 SWITCH_GROUP_TYPES ,
3331 SYSTEM ,
34- THERMOSTAT_CLASSES ,
3532 ZONE_THERMOSTATS ,
33+ ActuatorData ,
3634 ApplianceData ,
3735 DeviceData ,
3836 GatewayData ,
@@ -67,15 +65,31 @@ def update_for_cooling(self, devices: dict[str, DeviceData]) -> None:
6765 continue
6866
6967 if self .elga_cooling_enabled :
68+ # Replace setpoint with setpoint_high/_low
69+ thermostat = device ["thermostat" ]
7070 sensors = device ["sensors" ]
71- sensors ["setpoint_low" ] = sensors ["setpoint" ]
72- sensors ["setpoint_high" ] = MAX_SETPOINT
73- if self ._elga_cooling_active :
74- sensors ["setpoint_low" ] = MIN_SETPOINT
75- sensors ["setpoint_high" ] = sensors ["setpoint" ]
71+ max_setpoint = MAX_SETPOINT
72+ min_setpoint = MIN_SETPOINT
7673 if self ._sched_setpoints is not None :
77- sensors ["setpoint_low" ] = self ._sched_setpoints [0 ]
78- sensors ["setpoint_high" ] = self ._sched_setpoints [1 ]
74+ max_setpoint = self ._sched_setpoints [1 ]
75+ min_setpoint = self ._sched_setpoints [0 ]
76+
77+ temp_dict : ActuatorData = {
78+ "setpoint_low" : thermostat ["setpoint" ],
79+ "setpoint_high" : max_setpoint ,
80+ }
81+ if self ._elga_cooling_active :
82+ temp_dict = {
83+ "setpoint_low" : min_setpoint ,
84+ "setpoint_high" : thermostat ["setpoint" ],
85+ }
86+ if "setpoint" in sensors :
87+ sensors .pop ("setpoint" )
88+ sensors ["setpoint_low" ] = temp_dict ["setpoint_low" ]
89+ sensors ["setpoint_high" ] = temp_dict ["setpoint_high" ]
90+ thermostat .pop ("setpoint" )
91+ temp_dict .update (thermostat )
92+ device ["thermostat" ] = temp_dict
7993
8094 # For Adam + on/off cooling, modify heating_state and cooling_state
8195 # based on provided info by Plugwise
@@ -244,6 +258,9 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
244258 """
245259 details = self ._appl_data [dev_id ]
246260 device_data = self ._get_appliance_data (dev_id )
261+ # Remove thermostat-dict for thermo_sensors
262+ if details ["dev_class" ] == "thermo_sensor" :
263+ device_data .pop ("thermostat" )
247264
248265 # Generic
249266 if details ["dev_class" ] == "gateway" or dev_id == self .gateway_id :
@@ -270,7 +287,7 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
270287 # Specific, not generic Adam data
271288 device_data = self ._device_data_adam (details , device_data )
272289 # No need to obtain thermostat data when the device is not a thermostat
273- if details ["dev_class" ] not in THERMOSTAT_CLASSES :
290+ if details ["dev_class" ] not in ZONE_THERMOSTATS :
274291 return device_data
275292
276293 # Thermostat data (presets, temperatures etc)
@@ -639,35 +656,46 @@ async def set_preset(self, loc_id: str, preset: str) -> None:
639656
640657 await self ._request (uri , method = "put" , data = data )
641658
642- async def set_temperature (self , loc_id : str , temps : dict [str , Any ]) -> None :
659+ async def set_temperature (self , loc_id : str , items : dict [str , float ]) -> None :
643660 """Set the given Temperature on the relevant Thermostat."""
644- if "setpoint" in temps :
645- setpoint = temps ["setpoint" ]
646- elif self ._elga_cooling_active :
647- setpoint = temps ["setpoint_high" ]
648- else :
649- setpoint = temps ["setpoint_low" ]
650-
651- temp = str (setpoint )
661+ setpoint : float | None = None
662+ if "setpoint" in items :
663+ setpoint = items ["setpoint" ]
664+ if self .elga_cooling_enabled :
665+ if "setpoint_low" in items :
666+ setpoint = items ["setpoint_low" ]
667+ if self ._elga_cooling_active :
668+ if "setpoint_high" in items :
669+ setpoint = items ["setpoint_high" ]
670+
671+ if setpoint is None :
672+ raise PlugwiseError (
673+ "Plugwise: failed setting temperature: no valid input provided"
674+ ) # pragma: no cover
675+ temperature = str (setpoint )
652676 uri = self ._thermostat_uri (loc_id )
653677 data = (
654678 "<thermostat_functionality><setpoint>"
655- f"{ temp } </setpoint></thermostat_functionality>"
679+ f"{ temperature } </setpoint></thermostat_functionality>"
656680 )
657681
658682 await self ._request (uri , method = "put" , data = data )
659683
660- async def set_max_boiler_temperature (self , temperature : float ) -> None :
661- """Set the max. Boiler Temperature on the Central heating boiler."""
684+ async def set_number_setpoint (self , key : str , temperature : float ) -> None :
685+ """Set the max. Boiler or DHW setpoint on the Central Heating boiler."""
662686 temp = str (temperature )
687+ thermostat_id : str | None = None
663688 locator = f'appliance[@id="{ self ._heater_id } "]/actuator_functionalities/thermostat_functionality'
664- th_func = self ._appliances .find (locator )
665- if th_func .find ("type" ).text == "maximum_boiler_temperature" :
666- thermostat_id = th_func .attrib ["id" ]
689+ if th_func_list := self ._appliances .findall (locator ):
690+ for th_func in th_func_list :
691+ if th_func .find ("type" ).text == key :
692+ thermostat_id = th_func .attrib ["id" ]
693+
694+ if thermostat_id is None :
695+ raise PlugwiseError (f"Plugwise: cannot change setpoint, { key } not found." )
667696
668697 uri = f"{ APPLIANCES } ;id={ self ._heater_id } /thermostat;id={ thermostat_id } "
669698 data = f"<thermostat_functionality><setpoint>{ temp } </setpoint></thermostat_functionality>"
670-
671699 await self ._request (uri , method = "put" , data = data )
672700
673701 async def _set_groupswitch_member_state (
0 commit comments