From fc945f093cbb875c3ef716fabb583fcca8256374 Mon Sep 17 00:00:00 2001 From: Luke Mullan Date: Tue, 27 Jun 2017 14:52:01 +1000 Subject: [PATCH 1/2] Change to notification to use message even bus This will allow any plugin to listen for a notification and respond accordingly. --- modules/core/core.py | 4 +--- modules/notification/__init__.py | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/core/core.py b/modules/core/core.py index 60a6045..f61bb9e 100644 --- a/modules/core/core.py +++ b/modules/core/core.py @@ -224,9 +224,7 @@ class CraftBeerPi(ActorAPI, SensorAPI): def notify(self, headline, message, type="success", timeout=5000): self.beep() msg = {"id": str(uuid.uuid1()), "type": type, "headline": headline, "message": message, "timeout": timeout} - if timeout is None: - self.cache["messages"].append(msg) - self.emit("NOTIFY", msg) + self.emit_message(msg) def beep(self): if self.buzzer is not None: diff --git a/modules/notification/__init__.py b/modules/notification/__init__.py index 158beef..6276ef4 100644 --- a/modules/notification/__init__.py +++ b/modules/notification/__init__.py @@ -25,17 +25,16 @@ class NotificationView(FlaskView): return ('', 204) @cbpi.event("MESSAGE", async=True) -def messageEvent(message, **kwargs): +def messageEvent(message): """ React on message event. add the message to the cache and push the message to the clients :param message: the message :param kwargs: other parameter :return: None """ - - msg = {"id": len(cbpi.cache["messages"]), "type": "info", "message": message, "read": False} - cbpi.cache["messages"].append(msg) - cbpi.emit('MESSAGE', msg,) + if message["timeout"] is None: + cbpi.cache["messages"].append(message) + cbpi.emit("NOTIFY", message) @cbpi.initalizer(order=2) def init(cbpi): From 7d35538962cf0ae93b185f69eda7220134c5244b Mon Sep 17 00:00:00 2001 From: Luke Mullan Date: Wed, 28 Jun 2017 17:31:52 +1000 Subject: [PATCH 2/2] Fix **kwargs ommision. --- modules/notification/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/notification/__init__.py b/modules/notification/__init__.py index 6276ef4..2f440cb 100644 --- a/modules/notification/__init__.py +++ b/modules/notification/__init__.py @@ -25,7 +25,7 @@ class NotificationView(FlaskView): return ('', 204) @cbpi.event("MESSAGE", async=True) -def messageEvent(message): +def messageEvent(message, **kwargs): """ React on message event. add the message to the cache and push the message to the clients :param message: the message