removed async

This commit is contained in:
John Lancaster
2024-01-28 08:53:05 -06:00
parent 986996c595
commit 28d0541284

View File

@@ -1,5 +1,5 @@
from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.hass.hassapi import Hass
import asyncio
class SceneDetector(Hass): class SceneDetector(Hass):
def initialize(self): def initialize(self):
@@ -9,18 +9,25 @@ class SceneDetector(Hass):
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') self.log(f'Waiting for {self.scene_entity.friendly_name} to activate')
async def event_callback(self, event_name, data, cb_args): def event_callback(self, event_name, data, cb_args):
entity_id = data['service_data']['entity_id'] entity_id = data['service_data']['entity_id']
if entity_id == self.scene_entity.entity_id: if entity_id == self.scene_entity.entity_id:
await self.scene_detected() self.scene_detected()
async def scene_detected(self): def scene_detected(self):
self.log(f'Detected scene activation: {self.scene_entity.friendly_name}') self.log(f'Detected scene activation: {self.scene_entity.friendly_name}')
class MotionCanceller(SceneDetector): class MotionCanceller(SceneDetector):
async def scene_detected(self): def scene_detected(self):
await super().scene_detected() super().scene_detected()
await asyncio.sleep(0.5) # needed for when the scene gets turned on from everything being off because of competing callbacks app = self.get_app(self.args['app'])
app = await self.get_app(self.args['app']) try:
await app.cancel_motion_callback(new='off') self.run_in(
callback=lambda *args, **kwargs: app.cancel_motion_callback(),
delay=0.5
)
except:
self.log(f'Error cancelling motion callback for {self.args["app"]}', level='ERROR')
else:
self.log('Cancelled motion callback')