File: switch.py

package info (click to toggle)
python-miio 0.5.12-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,888 kB
  • sloc: python: 23,425; makefile: 9
file content (36 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (2)
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()