1 from Components.config import config
2 from Tools import Notifications
3 from Screens.MessageBox import MessageBox
5 from . import NOTIFICATIONID
7 def emergencyDisable(*args, **kwargs):
8 global growleeConnection
10 growleeConnection.stop()
12 if gotNotification in Notifications.notificationAdded:
13 Notifications.notificationAdded.remove(gotNotification)
14 Notifications.AddPopup(
15 _("Network error.\nDisabling Growlee until next restart!"),
16 MessageBox.TYPE_ERROR,
20 def gotNotification():
21 notifications = Notifications.notifications
23 _, screen, args, kwargs, id = notifications[-1]
24 if screen is MessageBox and id != NOTIFICATIONID and id not in config.plugins.growlee.blacklist.value:
26 # NOTE: priority is in [-2; 2] but type is [0; 3] so map it
27 # XXX: maybe priority==type-2 would be more appropriate
28 priority = kwargs.get("type", 0) - 1
29 timeout = kwargs.get("timeout", -1)
32 description = kwargs["text"]
35 description = description.decode('utf-8')
37 growleeConnection.sendNotification(title="Dreambox", description=description, priority=priority, timeout=timeout)
39 class GrowleeConnection:
42 def sendNotification(self, title="Dreambox", description='', priority=-1, timeout=-1):
44 level = int(config.plugins.growlee.level.value)
48 if self.connection and not priority < level:
49 self.connection.sendNotification(title=title, description=description, priority=priority, timeout=timeout)
55 proto = config.plugins.growlee.protocol.value
57 from Prowl import ProwlAPI
58 self.connection = ProwlAPI()
59 elif proto == "growl":
60 from GrowlTalk import GrowlTalkAbstraction
61 self.connection = GrowlTalkAbstraction()
62 else: # proto == "snarl":
63 from SNP import SnarlNetworkProtocolAbstraction
64 self.connection = SnarlNetworkProtocolAbstraction()
68 d = self.connection.stop()
69 self.connection = None
73 growleeConnection = GrowleeConnection()