Added WeMo Switch plugin

This commit is contained in:
Fabio Manganiello 2017-11-04 00:13:22 +01:00
parent 92970a83d6
commit 6a8a17eabd
3 changed files with 71 additions and 0 deletions

View file

@ -3,6 +3,10 @@ import mpd
from .. import MusicPlugin from .. import MusicPlugin
class MusicMpdPlugin(MusicPlugin): class MusicMpdPlugin(MusicPlugin):
_requires = [
'mpd'
]
def _init(self): def _init(self):
self.client = mpd.MPDClient(use_unicode=True) self.client = mpd.MPDClient(use_unicode=True)
self.client.connect(self.config['host'], self.config['port']) self.client.connect(self.config['host'], self.config['port'])

View file

@ -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:

View file

@ -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: