Browse Source

Change to notification to use message even bus

This will allow any plugin to listen for a notification and respond accordingly.
tags/3.1_alpha
Luke Mullan 8 years ago
parent
commit
fc945f093c
2 changed files with 5 additions and 8 deletions
  1. +1
    -3
      modules/core/core.py
  2. +4
    -5
      modules/notification/__init__.py

+ 1
- 3
modules/core/core.py View File

@@ -224,9 +224,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
def notify(self, headline, message, type="success", timeout=5000): def notify(self, headline, message, type="success", timeout=5000):
self.beep() self.beep()
msg = {"id": str(uuid.uuid1()), "type": type, "headline": headline, "message": message, "timeout": timeout} 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): def beep(self):
if self.buzzer is not None: if self.buzzer is not None:


+ 4
- 5
modules/notification/__init__.py View File

@@ -25,17 +25,16 @@ class NotificationView(FlaskView):
return ('', 204) return ('', 204)


@cbpi.event("MESSAGE", async=True) @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 React on message event. add the message to the cache and push the message to the clients
:param message: the message :param message: the message
:param kwargs: other parameter :param kwargs: other parameter
:return: None :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) @cbpi.initalizer(order=2)
def init(cbpi): def init(cbpi):


Loading…
Cancel
Save