From 6a8a17eabd18e4a6409911398d0b0ec3d34d3088 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 4 Nov 2017 00:13:22 +0100 Subject: [PATCH] Added WeMo Switch plugin --- runbullet/plugins/music/mpd/__init__.py | 4 +++ runbullet/plugins/switch/__init__.py | 28 ++++++++++++++++ runbullet/plugins/switch/wemo/__init__.py | 39 +++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 runbullet/plugins/switch/__init__.py create mode 100644 runbullet/plugins/switch/wemo/__init__.py diff --git a/runbullet/plugins/music/mpd/__init__.py b/runbullet/plugins/music/mpd/__init__.py index 9ea37a9ce..ba5e32dba 100644 --- a/runbullet/plugins/music/mpd/__init__.py +++ b/runbullet/plugins/music/mpd/__init__.py @@ -3,6 +3,10 @@ import mpd from .. import MusicPlugin class MusicMpdPlugin(MusicPlugin): + _requires = [ + 'mpd' + ] + def _init(self): self.client = mpd.MPDClient(use_unicode=True) self.client.connect(self.config['host'], self.config['port']) diff --git a/runbullet/plugins/switch/__init__.py b/runbullet/plugins/switch/__init__.py new file mode 100644 index 000000000..a968f1b88 --- /dev/null +++ b/runbullet/plugins/switch/__init__.py @@ -0,0 +1,28 @@ +from .. import Plugin + +class SwitchPlugin(Plugin): + def run(self, args): + if 'on' in args and args['on']: + self.on(args) + elif 'off' in args and args['off']: + self.off(args) + elif 'toggle' in args and args['toggle']: + self.toggle(args) + + return self.status() + + def on(self, args): + raise NotImplementedError() + + def off(self, args): + raise NotImplementedError() + + def toggle(self, args): + raise NotImplementedError() + + def status(self): + raise NotImplementedError() + + +# vim:sw=4:ts=4:et: + diff --git a/runbullet/plugins/switch/wemo/__init__.py b/runbullet/plugins/switch/wemo/__init__.py new file mode 100644 index 000000000..134712684 --- /dev/null +++ b/runbullet/plugins/switch/wemo/__init__.py @@ -0,0 +1,39 @@ +import logging + +from ouimeaux.environment import Environment, UnknownDevice + +from .. import SwitchPlugin + +class SwitchWemoPlugin(SwitchPlugin): + _requires = [ + 'ouimeaux' + ] + + def _init(self): + logging.basicConfig(level=logging.INFO) + + self.env = Environment() + self.env.start() + logging.info('Starting WeMo discovery') + self.env.discover(seconds=3) + + def on(self, args): + switch = self.env.get_switch(args['device']) + logging.info('Turning {} on'.format(args['device'])) + switch.on() + + def off(self, args): + switch = self.env.get_switch(args['device']) + logging.info('Turning {} off'.format(args['device'])) + switch.off() + + def toggle(self, args): + switch = self.env.get_switch(args['device']) + logging.info('Toggling {}'.format(args['device'])) + switch.toggle() + + def status(self): + return [''] + +# vim:sw=4:ts=4:et: +