@@ -380,6 +380,7 @@ async def set_switch_state(
380380 self , appl_id : str , members : list [str ] | None , model : str , state : str
381381 ) -> bool :
382382 """Set the given State of the relevant Switch."""
383+ current_state = self .gw_entities [appl_id ]["switches" ]["relay" ]
383384 requested_state = state == STATE_ON
384385 switch = Munch ()
385386 switch .actuator = "actuator_functionalities"
@@ -400,8 +401,16 @@ async def set_switch_state(
400401 switch .func = "lock"
401402 state = "true" if state == STATE_ON else "false"
402403
404+ data = (
405+ f"<{ switch .func_type } >"
406+ f"<{ switch .func } >{ state } </{ switch .func } >"
407+ f"</{ switch .func_type } >"
408+ )
409+
403410 if members is not None :
404- return await self ._set_groupswitch_member_state (members , state , switch )
411+ return await self ._set_groupswitch_member_state (
412+ appl_id , data , members , state , switch
413+ )
405414
406415 locator = f'appliance[@id="{ appl_id } "]/{ switch .actuator } /{ switch .func_type } '
407416 found = self ._domain_objects .findall (locator )
@@ -414,45 +423,36 @@ async def set_switch_state(
414423 else : # actuators with a single item like relay_functionality
415424 switch_id = item .attrib ["id" ]
416425
417- data = (
418- f"<{ switch .func_type } >"
419- f"<{ switch .func } >{ state } </{ switch .func } >"
420- f"</{ switch .func_type } >"
421- )
422426 uri = f"{ APPLIANCES } ;id={ appl_id } /{ switch .device } ;id={ switch_id } "
423- if model == "relay" and self .gw_entities [appl_id ]["switches" ][ "lock" ] :
427+ if model == "relay" and self .gw_entities [appl_id ]["switches" ]. get ( "lock" ) :
424428 # Don't switch a relay when its corresponding lock-state is true
425- return not requested_state
429+ return current_state
426430
427431 await self .call_request (uri , method = "put" , data = data )
428432 return requested_state
429433
430434 async def _set_groupswitch_member_state (
431- self , members : list [str ], state : str , switch : Munch
435+ self , appl_id : str , data : str , members : list [str ], state : str , switch : Munch
432436 ) -> bool :
433437 """Helper-function for set_switch_state().
434438
435439 Set the given State of the relevant Switch within a group of members.
436440 """
441+ current_state = self .gw_entities [appl_id ]["switches" ]["relay" ]
437442 requested_state = state == STATE_ON
438443 switched = 0
439444 for member in members :
440445 locator = f'appliance[@id="{ member } "]/{ switch .actuator } /{ switch .func_type } '
441446 switch_id = self ._domain_objects .find (locator ).attrib ["id" ]
442447 uri = f"{ APPLIANCES } ;id={ member } /{ switch .device } ;id={ switch_id } "
443- data = (
444- f"<{ switch .func_type } >"
445- f"<{ switch .func } >{ state } </{ switch .func } >"
446- f"</{ switch .func_type } >"
447- )
448448 if not self .gw_entities [member ]["switches" ].get ("lock" ):
449449 await self .call_request (uri , method = "put" , data = data )
450450 switched += 1
451451
452452 if switched > 0 :
453453 return requested_state
454454
455- return not requested_state
455+ return current_state
456456
457457 async def set_temperature (self , loc_id : str , items : dict [str , float ]) -> None :
458458 """Set the given Temperature on the relevant Thermostat."""
0 commit comments