1- """Plugwise Home Assistant module ."""
1+ """Plugwise backend module for Home Assistant Core ."""
22import asyncio
33import copy
44import logging
3636
3737
3838class Smile (SmileHelper ):
39- """Define the Plugwise object ."""
39+ """The Plugwise Smile main class ."""
4040
4141 # pylint: disable=too-many-instance-attributes, too-many-public-methods
4242
@@ -190,10 +190,6 @@ async def smile_detect(self, result, dsmrmain):
190190 self .stretch_v2 = self .smile_version [1 ].major == 2
191191 self .stretch_v3 = self .smile_version [1 ].major == 3
192192
193- async def close_connection (self ):
194- """Close the Plugwise connection."""
195- await self .websession .close ()
196-
197193 async def full_update_device (self ):
198194 """Perform a first fetch of all XML data, needed for initialization."""
199195 await self .update_domain_objects ()
@@ -208,7 +204,7 @@ async def full_update_device(self):
208204 self ._modules = await self .request (MODULES )
209205
210206 async def update_gw_devices (self ):
211- """Perform an incremental update for updating the various states."""
207+ """Perform an incremental update for updating the various device states."""
212208 await self .update_domain_objects ()
213209
214210 # P1 legacy has no appliances
@@ -234,7 +230,7 @@ async def update_gw_devices(self):
234230
235231 def all_device_data (self ):
236232 """Helper-function for get_all_devices().
237- Collect data for each device and add to self.gw_devices.
233+ Collect initial data for each device and add to self.gw_devices.
238234 """
239235 dev_id_list = []
240236 dev_and_data_list = []
@@ -353,7 +349,9 @@ def device_data_climate(self, details, device_data):
353349 return device_data
354350
355351 def get_device_data (self , dev_id ):
356- """Provide device-data, based on location_id, from APPLIANCES."""
352+ """Helper-function for all_device_data() and update_gw_devices().
353+ Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
354+ """
357355 devices = self .devices
358356 details = devices .get (dev_id )
359357 device_data = self .appliance_data (dev_id )
@@ -389,7 +387,9 @@ def get_device_data(self, dev_id):
389387 return device_data
390388
391389 def single_master_thermostat (self ):
392- """Determine if there is a single master thermostat in the setup."""
390+ """Determine if there is a single master thermostat in the setup.
391+ Possible output: None, True, False.
392+ """
393393 if self .smile_type != "thermostat" :
394394 self .thermo_locs = self .match_locations ()
395395 return None
@@ -405,10 +405,34 @@ def single_master_thermostat(self):
405405 return True
406406 return False
407407
408- async def set_schedule_state (self , loc_id , name , state ):
409- """
410- Set the schedule, with the given name, connected to a location.
408+ async def set_schedule_state_legacy (self , name , state ):
409+ """Helper-function for set_schedule_state()."""
410+ schema_rule_id = None
411+ for rule in self ._domain_objects .findall ("rule" ):
412+ if rule .find ("name" ).text == name :
413+ schema_rule_id = rule .attrib ["id" ]
414+
415+ if schema_rule_id is None :
416+ return False
417+
418+ template_id = None
419+ state = str (state )
420+ locator = f'.//*[@id="{ schema_rule_id } "]/template'
421+ for rule in self ._domain_objects .findall (locator ):
422+ template_id = rule .attrib ["id" ]
423+
424+ uri = f"{ RULES } ;id={ schema_rule_id } "
425+ data = (
426+ "<rules><rule"
427+ f' id="{ schema_rule_id } "><name><![CDATA[{ name } ]]></name><template'
428+ f' id="{ template_id } " /><active>{ state } </active></rule></rules>'
429+ )
430+
431+ await self .request (uri , method = "put" , data = data )
432+ return True
411433
434+ async def set_schedule_state (self , loc_id , name , state ):
435+ """Set the Schedule, with the given name, on the relevant Thermostat.
412436 Determined from - DOMAIN_OBJECTS.
413437 """
414438 if self ._smile_legacy :
@@ -438,7 +462,7 @@ async def set_schedule_state(self, loc_id, name, state):
438462 return True
439463
440464 async def set_preset (self , loc_id , preset ):
441- """Set the given location-preset on the relevant thermostat - from LOCATIONS."""
465+ """Set the given Preset on the relevant Thermostat - from LOCATIONS."""
442466 if self ._smile_legacy :
443467 return await self .set_preset_legacy (preset )
444468
@@ -460,7 +484,7 @@ async def set_preset(self, loc_id, preset):
460484 return True
461485
462486 async def set_temperature (self , loc_id , temperature ):
463- """Send temperature-set request to the locations thermostat ."""
487+ """Set the given Temperature on the relevant Thermostat ."""
464488 temperature = str (temperature )
465489 uri = self .temperature_uri (loc_id )
466490 data = (
@@ -472,7 +496,9 @@ async def set_temperature(self, loc_id, temperature):
472496 return True
473497
474498 async def set_groupswitch_member_state (self , members , state , switch ):
475- """Switch the Switch within a group of members off/on."""
499+ """ Helper-function for set_switch_state() .
500+ Set the given State of the relevant Switch within a group of members.
501+ """
476502 for member in members :
477503 locator = f'appliance[@id="{ member } "]/{ switch .actuator } /{ switch .func_type } '
478504 switch_id = self ._appliances .find (locator ).attrib ["id" ]
@@ -487,7 +513,7 @@ async def set_groupswitch_member_state(self, members, state, switch):
487513 return True
488514
489515 async def set_switch_state (self , appl_id , members , model , state ):
490- """Switch the Switch off/on ."""
516+ """Set the given State of the relevant Switch ."""
491517 switch = Munch ()
492518 switch .actuator = "actuator_functionalities"
493519 switch .device = "relay"
@@ -531,7 +557,7 @@ async def set_switch_state(self, appl_id, members, model, state):
531557 return True
532558
533559 async def set_preset_legacy (self , preset ):
534- """Set the given preset on the thermostat - from DOMAIN_OBJECTS."""
560+ """Set the given Preset on the relevant Thermostat - from DOMAIN_OBJECTS."""
535561 locator = f'rule/directives/when/then[@icon="{ preset } "].../.../...'
536562 rule = self ._domain_objects .find (locator )
537563 if rule is None :
@@ -543,34 +569,8 @@ async def set_preset_legacy(self, preset):
543569 await self .request (uri , method = "put" , data = data )
544570 return True
545571
546- async def set_schedule_state_legacy (self , name , state ):
547- """Send a set request to the schema with the given name."""
548- schema_rule_id = None
549- for rule in self ._domain_objects .findall ("rule" ):
550- if rule .find ("name" ).text == name :
551- schema_rule_id = rule .attrib ["id" ]
552-
553- if schema_rule_id is None :
554- return False
555-
556- template_id = None
557- state = str (state )
558- locator = f'.//*[@id="{ schema_rule_id } "]/template'
559- for rule in self ._domain_objects .findall (locator ):
560- template_id = rule .attrib ["id" ]
561-
562- uri = f"{ RULES } ;id={ schema_rule_id } "
563- data = (
564- "<rules><rule"
565- f' id="{ schema_rule_id } "><name><![CDATA[{ name } ]]></name><template'
566- f' id="{ template_id } " /><active>{ state } </active></rule></rules>'
567- )
568-
569- await self .request (uri , method = "put" , data = data )
570- return True
571-
572572 async def delete_notification (self ):
573- """Send a set request to the schema with the given name ."""
573+ """Delete the active Plugwise Notification ."""
574574 uri = f"{ NOTIFICATIONS } "
575575
576576 await self .request (uri , method = "delete" )
0 commit comments