1 from Components.config import config
2 from Tools import Notifications
3 from Screens.MessageBox import MessageBox
4 from twisted.internet.defer import Deferred
5 from twisted.internet import reactor
7 from . import NOTIFICATIONID
9 def emergencyDisable(*args, **kwargs):
10 global growleeConnection
12 growleeConnection.stop()
14 if gotNotification in Notifications.notificationAdded:
15 Notifications.notificationAdded.remove(gotNotification)
16 Notifications.AddPopup(
17 _("Network error.\nDisabling Growlee until next restart!"),
18 MessageBox.TYPE_ERROR,
22 def gotNotification():
23 notifications = Notifications.notifications
25 _, screen, args, kwargs, id = notifications[-1]
26 if screen is MessageBox and id != NOTIFICATIONID:
28 # NOTE: priority is in [-2; 2] but type is [0; 3] so map it
29 # XXX: maybe priority==type-2 would be more appropriate
30 priority = kwargs.get("type", 0) - 1
31 timeout = kwargs.get("timeout", -1)
34 description = kwargs["text"]
37 description = description
39 growleeConnection.sendNotification(title="Dreambox", description=description, priority=priority, timeout=timeout, id=id)
41 class GrowleeConnection:
45 def sendNotification(self, title="Dreambox", description='', priority=-1, timeout=-1, id=""):
46 for connection, host in self.connections:
48 level = int(host.level.value)
52 if connection and id not in host.blacklist.value and not priority < level:
53 connection.sendNotification(title=title, description=description, priority=priority, timeout=timeout)
59 for host in config.plugins.growlee.hosts:
60 if not (host.enable_outgoing.value or host.enable_incoming.value):
63 proto = host.protocol.value
65 from Prowl import ProwlAPI
66 connection = ProwlAPI(host)
67 elif proto == "growl":
68 from GrowlTalk import GrowlTalkAbstraction
69 connection = GrowlTalkAbstraction(host)
70 else: # proto == "snarl":
71 from SNP import SnarlNetworkProtocolAbstraction
72 connection = SnarlNetworkProtocolAbstraction(host)
74 self.connections.append((connection, host))
76 def maybeClose(self, resOrFail, defer = None):
79 if defer: defer.callback(True)
84 for connection, host in self.connections:
88 d.addBoth(self.maybeClose, defer = defer)
89 del self.connections[:]
92 reactor.callLater(1, defer, True)
95 growleeConnection = GrowleeConnection()