@@ -480,21 +480,6 @@ def _appl_dhw_mode_info(self, appl: Munch, appliance: etree) -> Munch:
480480
481481 return appl
482482
483- def _control_state (self , loc_id : str ) -> str | bool :
484- """Helper-function for _device_data_adam().
485-
486- Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
487- Represents the heating/cooling demand-state of the local master thermostat.
488- Note: heating or cooling can still be active when the setpoint has been reached.
489- """
490- locator = f'location[@id="{ loc_id } "]'
491- if (location := self ._domain_objects .find (locator )) is not None :
492- locator = './actuator_functionalities/thermostat_functionality[type="thermostat"]/control_state'
493- if (ctrl_state := location .find (locator )) is not None :
494- return str (ctrl_state .text )
495-
496- return False
497-
498483 def _get_appliances_with_offset_functionality (self ) -> list [str ]:
499484 """Helper-function collecting all appliance that have offset_functionality."""
500485 therm_list : list [str ] = []
@@ -506,63 +491,6 @@ def _get_appliances_with_offset_functionality(self) -> list[str]:
506491
507492 return therm_list
508493
509- def _presets (self , loc_id : str ) -> dict [str , list [float ]]:
510- """Collect Presets for a Thermostat based on location_id."""
511- presets : dict [str , list [float ]] = {}
512- tag_1 = "zone_setpoint_and_state_based_on_preset"
513- tag_2 = "Thermostat presets"
514- if not (rule_ids := self ._rule_ids_by_tag (tag_1 , loc_id )):
515- if not (rule_ids := self ._rule_ids_by_name (tag_2 , loc_id )):
516- return presets # pragma: no cover
517-
518- for rule_id in rule_ids :
519- directives : etree = self ._domain_objects .find (
520- f'rule[@id="{ rule_id } "]/directives'
521- )
522- for directive in directives :
523- preset = directive .find ("then" ).attrib
524- presets [directive .attrib ["preset" ]] = [
525- float (preset ["heating_setpoint" ]),
526- float (preset ["cooling_setpoint" ]),
527- ]
528-
529- return presets
530-
531- def _rule_ids_by_name (self , name : str , loc_id : str ) -> dict [str , dict [str , str ]]:
532- """Helper-function for _presets().
533-
534- Obtain the rule_id from the given name and and provide the location_id, when present.
535- """
536- schedule_ids : dict [str , dict [str , str ]] = {}
537- locator = f'./contexts/context/zone/location[@id="{ loc_id } "]'
538- for rule in self ._domain_objects .findall (f'./rule[name="{ name } "]' ):
539- active = rule .find ("active" ).text
540- if rule .find (locator ) is not None :
541- schedule_ids [rule .attrib ["id" ]] = {"location" : loc_id , "name" : name , "active" : active }
542- else :
543- schedule_ids [rule .attrib ["id" ]] = {"location" : NONE , "name" : name , "active" : active }
544-
545- return schedule_ids
546-
547- def _rule_ids_by_tag (self , tag : str , loc_id : str ) -> dict [str , dict [str , str ]]:
548- """Helper-function for _presets(), _schedules() and _last_active_schedule().
549-
550- Obtain the rule_id from the given template_tag and provide the location_id, when present.
551- """
552- schedule_ids : dict [str , dict [str , str ]] = {}
553- locator1 = f'./template[@tag="{ tag } "]'
554- locator2 = f'./contexts/context/zone/location[@id="{ loc_id } "]'
555- for rule in self ._domain_objects .findall ("./rule" ):
556- if rule .find (locator1 ) is not None :
557- name = rule .find ("name" ).text
558- active = rule .find ("active" ).text
559- if rule .find (locator2 ) is not None :
560- schedule_ids [rule .attrib ["id" ]] = {"location" : loc_id , "name" : name , "active" : active }
561- else :
562- schedule_ids [rule .attrib ["id" ]] = {"location" : NONE , "name" : name , "active" : active }
563-
564- return schedule_ids
565-
566494 def _get_measurement_data (self , dev_id : str ) -> DeviceData :
567495 """Helper-function for smile.py: _get_device_data().
568496
@@ -1060,15 +988,20 @@ def _rank_thermostat(
1060988 else :
1061989 self ._thermo_locs [loc_id ]["slaves" ].add (appliance_id )
1062990
1063- def _thermostat_uri (self , loc_id : str ) -> str :
1064- """Helper-function for smile.py: set_temperature ().
991+ def _control_state (self , loc_id : str ) -> str | bool :
992+ """Helper-function for _device_data_adam ().
1065993
1066- Determine the location-set_temperature uri - from LOCATIONS.
994+ Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
995+ Represents the heating/cooling demand-state of the local master thermostat.
996+ Note: heating or cooling can still be active when the setpoint has been reached.
1067997 """
1068- locator = f'./location[@id="{ loc_id } "]/actuator_functionalities/thermostat_functionality'
1069- thermostat_functionality_id = self ._domain_objects .find (locator ).attrib ["id" ]
998+ locator = f'location[@id="{ loc_id } "]'
999+ if (location := self ._domain_objects .find (locator )) is not None :
1000+ locator = './actuator_functionalities/thermostat_functionality[type="thermostat"]/control_state'
1001+ if (ctrl_state := location .find (locator )) is not None :
1002+ return str (ctrl_state .text )
10701003
1071- return f" { LOCATIONS } ;id= { loc_id } /thermostat;id= { thermostat_functionality_id } "
1004+ return False
10721005
10731006 def _heating_valves (self ) -> int | bool :
10741007 """Helper-function for smile.py: _device_data_adam().
@@ -1098,6 +1031,63 @@ def _preset(self, loc_id: str) -> str | None:
10981031
10991032 return None # pragma: no cover
11001033
1034+ def _presets (self , loc_id : str ) -> dict [str , list [float ]]:
1035+ """Collect Presets for a Thermostat based on location_id."""
1036+ presets : dict [str , list [float ]] = {}
1037+ tag_1 = "zone_setpoint_and_state_based_on_preset"
1038+ tag_2 = "Thermostat presets"
1039+ if not (rule_ids := self ._rule_ids_by_tag (tag_1 , loc_id )):
1040+ if not (rule_ids := self ._rule_ids_by_name (tag_2 , loc_id )):
1041+ return presets # pragma: no cover
1042+
1043+ for rule_id in rule_ids :
1044+ directives : etree = self ._domain_objects .find (
1045+ f'rule[@id="{ rule_id } "]/directives'
1046+ )
1047+ for directive in directives :
1048+ preset = directive .find ("then" ).attrib
1049+ presets [directive .attrib ["preset" ]] = [
1050+ float (preset ["heating_setpoint" ]),
1051+ float (preset ["cooling_setpoint" ]),
1052+ ]
1053+
1054+ return presets
1055+
1056+ def _rule_ids_by_name (self , name : str , loc_id : str ) -> dict [str , dict [str , str ]]:
1057+ """Helper-function for _presets().
1058+
1059+ Obtain the rule_id from the given name and and provide the location_id, when present.
1060+ """
1061+ schedule_ids : dict [str , dict [str , str ]] = {}
1062+ locator = f'./contexts/context/zone/location[@id="{ loc_id } "]'
1063+ for rule in self ._domain_objects .findall (f'./rule[name="{ name } "]' ):
1064+ active = rule .find ("active" ).text
1065+ if rule .find (locator ) is not None :
1066+ schedule_ids [rule .attrib ["id" ]] = {"location" : loc_id , "name" : name , "active" : active }
1067+ else :
1068+ schedule_ids [rule .attrib ["id" ]] = {"location" : NONE , "name" : name , "active" : active }
1069+
1070+ return schedule_ids
1071+
1072+ def _rule_ids_by_tag (self , tag : str , loc_id : str ) -> dict [str , dict [str , str ]]:
1073+ """Helper-function for _presets(), _schedules() and _last_active_schedule().
1074+
1075+ Obtain the rule_id from the given template_tag and provide the location_id, when present.
1076+ """
1077+ schedule_ids : dict [str , dict [str , str ]] = {}
1078+ locator1 = f'./template[@tag="{ tag } "]'
1079+ locator2 = f'./contexts/context/zone/location[@id="{ loc_id } "]'
1080+ for rule in self ._domain_objects .findall ("./rule" ):
1081+ if rule .find (locator1 ) is not None :
1082+ name = rule .find ("name" ).text
1083+ active = rule .find ("active" ).text
1084+ if rule .find (locator2 ) is not None :
1085+ schedule_ids [rule .attrib ["id" ]] = {"location" : loc_id , "name" : name , "active" : active }
1086+ else :
1087+ schedule_ids [rule .attrib ["id" ]] = {"location" : NONE , "name" : name , "active" : active }
1088+
1089+ return schedule_ids
1090+
11011091 def _schedules (self , location : str ) -> tuple [list [str ], str ]:
11021092 """Helper-function for smile.py: _device_data_climate().
11031093
@@ -1154,3 +1144,13 @@ def _last_used_schedule(self, schedules: list[str]) -> str:
11541144 schedules_dates [name ] = (schedule_time - epoch ).total_seconds ()
11551145
11561146 return sorted (schedules_dates .items (), key = lambda kv : kv [1 ])[- 1 ][0 ]
1147+
1148+ def _thermostat_uri (self , loc_id : str ) -> str :
1149+ """Helper-function for smile.py: set_temperature().
1150+
1151+ Determine the location-set_temperature uri - from LOCATIONS.
1152+ """
1153+ locator = f'./location[@id="{ loc_id } "]/actuator_functionalities/thermostat_functionality'
1154+ thermostat_functionality_id = self ._domain_objects .find (locator ).attrib ["id" ]
1155+
1156+ return f"{ LOCATIONS } ;id={ loc_id } /thermostat;id={ thermostat_functionality_id } "
0 commit comments