From 643fd90ff08e36652c95fc208b779b9d0a8dc031 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 00:53:06 -0600 Subject: [PATCH] more callbacks --- motion.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/motion.py b/motion.py index daa8f63..038c0ce 100644 --- a/motion.py +++ b/motion.py @@ -89,21 +89,20 @@ class Motion(Hass): } return callbacks - # def get_sensor_callbacks(self): - # return { - # handle: info - # for handle, info in self.get_app_callbacks().items() - # if info['entity'] == self.sensor - # } + def get_sensor_callbacks(self): + return { + handle: info + for handle, info in self.get_app_callbacks().items() + if info['entity'] == self.sensor.entity_id + } def cancel_motion_callback(self, new: str): - callbacks = self.get_app_callbacks() + callbacks = self.get_sensor_callbacks() # self.log(f'Found {len(callbacks)}') for handle, info in callbacks.items(): entity = info["entity"] new_match = re.match('new=(?P.*?)\s', info['kwargs']) # self.log(f'{handle}: {info["entity"]}: {info["kwargs"]}') - if new_match is not None: - if new_match.group("new") == new and entity == self.sensor.entity_id: - self.cancel_listen_state(handle) - self.log(f'cancelled: {self.friendly_name(entity)}: {new}') + if new_match is not None and new_match.group("new") == new: + self.cancel_listen_state(handle) + self.log(f'cancelled: {self.friendly_name(entity)}: {new}')