platypush/platypush/plugins/switch/__init__.py

46 lines
1.1 KiB
Python
Raw Normal View History

from platypush.plugins import Plugin, action
2017-11-04 00:13:22 +01:00
2019-07-02 12:02:28 +02:00
2017-11-04 00:13:22 +01:00
class SwitchPlugin(Plugin):
2018-06-25 19:57:43 +02:00
"""
Abstract class for interacting with switch devices
"""
2019-07-02 12:02:28 +02:00
def __init__(self, **kwargs):
super().__init__(**kwargs)
@action
2019-07-02 12:02:28 +02:00
def on(self, device, *args, **kwargs):
2018-06-25 19:57:43 +02:00
""" Turn the device on """
2017-11-04 00:13:22 +01:00
raise NotImplementedError()
@action
2019-07-02 12:02:28 +02:00
def off(self, device, *args, **kwargs):
2018-06-25 19:57:43 +02:00
""" Turn the device off """
2017-11-04 00:13:22 +01:00
raise NotImplementedError()
@action
2019-07-02 12:02:28 +02:00
def toggle(self, device, *args, **kwargs):
2018-06-25 19:57:43 +02:00
""" Toggle the device status (on/off) """
2017-11-04 00:13:22 +01:00
raise NotImplementedError()
@action
2019-07-02 12:02:28 +02:00
def status(self, device=None, *args, **kwargs):
""" Get the status of a specified device or of all the configured devices (default)"""
devices = self.devices
if device:
devices = [d for d in self.devices if d.get('id') == device or d.get('name') == device]
if devices:
return self.devices.pop(0)
else:
return None
return devices
@property
def devices(self):
2017-11-04 00:13:22 +01:00
raise NotImplementedError()
# vim:sw=4:ts=4:et: