formatting

This commit is contained in:
John Lancaster
2024-05-07 23:37:34 -05:00
parent a38341484d
commit 8eb9e84b9d
4 changed files with 50 additions and 43 deletions

View File

@@ -3,12 +3,18 @@ from appdaemon.plugins.hass.hassapi import Hass
class SceneDetector(Hass):
def initialize(self):
self.scene_entity = self.args['scene'] if self.args['scene'].startswith('scene.') else f'scene.{self.args["scene"]}'
self.scene_entity = (
self.args['scene']
if self.args['scene'].startswith('scene.')
else f'scene.{self.args["scene"]}'
)
self.scene_entity = self.get_entity(self.scene_entity)
self.listen_event(self.event_callback, event='call_service', domain='scene', service='turn_on')
self.listen_event(
self.event_callback, event='call_service', domain='scene', service='turn_on'
)
self.log(f'Waiting for {self.scene_entity.friendly_name} to activate')
def event_callback(self, event_name, data, cb_args):
entity_id = data['service_data']['entity_id']
if entity_id == self.scene_entity.entity_id:
@@ -23,11 +29,11 @@ class MotionCanceller(SceneDetector):
super().scene_detected()
app = self.get_app(self.args['app'])
try:
self.run_in(
callback=lambda *args, **kwargs: app.cancel_motion_callback(),
delay=0.5
)
self.run_in(callback=lambda *args, **kwargs: app.cancel_motion_callback(), delay=0.5)
except Exception:
self.log(f'Error cancelling motion callback for {self.args["app"]}', level='ERROR')
self.log(
f'Error cancelling motion callback for {self.args["app"]}',
level='ERROR',
)
else:
self.log('Cancelled motion callback')