forked from platypush/platypush
Added WeMo Switch plugin
This commit is contained in:
parent
92970a83d6
commit
6a8a17eabd
3 changed files with 71 additions and 0 deletions
|
@ -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'])
|
||||
|
|
28
runbullet/plugins/switch/__init__.py
Normal file
28
runbullet/plugins/switch/__init__.py
Normal 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:
|
||||
|
39
runbullet/plugins/switch/wemo/__init__.py
Normal file
39
runbullet/plugins/switch/wemo/__init__.py
Normal 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:
|
||||
|
Loading…
Reference in a new issue