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
|
"""Xiaomi Zigbee switches."""
from enum import IntEnum
import click
from ...click_common import command
from .subdevice import SubDevice
class Switch(SubDevice):
"""Base class for one channel switch subdevice that supports on/off."""
class ChannelMap(IntEnum):
"""Option to select wich channel to control."""
channel_0 = 0
channel_1 = 1
channel_2 = 2
@command(click.argument("channel", type=int))
def toggle(self, channel: int = 0):
"""Toggle a channel of the switch, default channel_0."""
return self.send_arg(
self.setter, [self.ChannelMap(channel).name, "toggle"]
).pop()
@command(click.argument("channel", type=int))
def on(self, channel: int = 0):
"""Turn on a channel of the switch, default channel_0."""
return self.send_arg(self.setter, [self.ChannelMap(channel).name, "on"]).pop()
@command(click.argument("channel", type=int))
def off(self, channel: int = 0):
"""Turn off a channel of the switch, default channel_0."""
return self.send_arg(self.setter, [self.ChannelMap(channel).name, "off"]).pop()
|