summaryrefslogtreecommitdiffstats
path: root/__init__.py
blob: 1b91a788912eee0edd6a45c0ad0b15ea0a7d414f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding=utf-8
from __future__ import absolute_import
from sleekxmpp import ClientXMPP
import octoprint.plugin

class OctoXMPP(octoprint.plugin.EventHandlerPlugin,
                    octoprint.plugin.SettingsPlugin):

    def initialize(self):
        jid = self._settings.get("username")
        passwd = self._settings.get("password")

        self._xmpp = ClientXMPP(jid, passwd)
        self._xmpp.add_event_handler("session_start", self._xmpp.send_presence)

        self._xmpp.connect()
        self._xmpp.process(block=False)

    def get_settings_defaults(self):
        return dict(jid="rupert@derflob.de", password="KosselMini", receivers=["derflob@derflob.de", "jabber@dermeb.de"])

    def _msg_receivers(self, msg):
        for r in self._settings.get("receivers"):
            self._xmpp.send_message(mto=r, mbody=msg)

    def on_event(self, event, data):
        if (event == "PrintDone"):
            self._msg_receivers("Zack, Feditsch!")
        elif (event == "PrintFailed"):
            self._msg_receivers("Da ging was schief!")
        elif (event == "PrintPaused"):
            self._msg_receivers("Druck pausiert.")
        elif (event == "PrintResumed"):
            self._msg_receivers("Druck resümiert.")
        elif (event == "PrintCancelled"):
            self._msg_receivers("Druck abgebrochen!")
        else:
            self._xmpp.send_message(mto="derflob@derflob.de", mbody=event)

__plugin_name__ = "OctoXMPP"
__plugin_version__ = "0.1.0"
__plugin_description__ = "Notify about some Events over XMPP."
__plugin_implementation__ = OctoXMPP()