From cde20f647d9c54646c924f882f21fc45c3934896 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 2 Dec 2022 20:25:27 +0100 Subject: [PATCH] fix notify on error --- cbpi/__init__.py | 2 +- cbpi/controller/notification_controller.py | 29 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 2260e28..0618f27 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.0.7.rc2" +__version__ = "4.0.7.rc3" __codename__ = "November Rain" diff --git a/cbpi/controller/notification_controller.py b/cbpi/controller/notification_controller.py index 33e6fb1..eb105d6 100644 --- a/cbpi/controller/notification_controller.py +++ b/cbpi/controller/notification_controller.py @@ -12,24 +12,25 @@ class NotificationController: ''' self.cbpi = cbpi self.logger = logging.getLogger(__name__) - NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No") - if NOTIFY_ON_ERROR == "Yes": - logging.root.addFilter(self.notify_log_event) + logging.root.addFilter(self.notify_log_event) self.callback_cache = {} self.listener = {} def notify_log_event(self, record): - try: - if record.levelno > 20: - # on log events higher then INFO we want to notify all clients - type = NotificationType.WARNING - if record.levelno > 30: - type = NotificationType.ERROR - self.cbpi.notify(title=f"{record.levelname}", message=record.msg, type = type) - except Exception as e: - pass - finally: - return True + NOTIFY_ON_ERROR = self.cbpi.config.get("NOTIFY_ON_ERROR", "No") + if NOTIFY_ON_ERROR == "Yes": + try: + if record.levelno > 20: + # on log events higher then INFO we want to notify all clients + type = NotificationType.WARNING + if record.levelno > 30: + type = NotificationType.ERROR + self.cbpi.notify(title=f"{record.levelname}", message=record.msg, type = type) + except Exception as e: + pass + finally: + return True + return True def add_listener(self, method): listener_id = shortuuid.uuid()