Refactor auto switch handling in SmartSwitch to use dedicated methods for state changes
This commit is contained in:
@@ -155,8 +155,12 @@ class SmartSwitch(SmartObject):
|
|||||||
# Timer callback: applies the deferred state set by auto_switch_*_after.
|
# Timer callback: applies the deferred state set by auto_switch_*_after.
|
||||||
def on_auto_switch_after(self, kwargs):
|
def on_auto_switch_after(self, kwargs):
|
||||||
self.auto_switch_cb_handle = None
|
self.auto_switch_cb_handle = None
|
||||||
self.log(f"Switching {self.entity_id} {kwargs['new_state']} after {kwargs['autoswitch_delay']}s")
|
new_state = kwargs['new_state']
|
||||||
self.set_state(self.entity_id,state = kwargs['new_state'])
|
self.log(f"Switching {self.entity_id} {new_state} after {kwargs['autoswitch_delay']}s")
|
||||||
|
if new_state == 'on':
|
||||||
|
self.switch_on()
|
||||||
|
else:
|
||||||
|
self.switch_off()
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Public switch API
|
# Public switch API
|
||||||
|
|||||||
Reference in New Issue
Block a user