Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support of Aqara Wireless Relay 2ch (LLKZMK11LM) #696

Merged
merged 5 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions devtools/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def __str__(self):
def as_code(self):
s = ""
s += f"class {pretty_name(self.description)}(MiOTService):\n"
s += f' """\n'
s += ' """\n'
s += f" {self.description} ({self.type}) (siid: {self.iid})\n"
s += f" Events: {len(self.events)}\n"
s += f" Properties: {len(self.properties)}\n"
s += f" Actions: {len(self.actions)}\n"
s += f' """\n\n'
s += ' """\n\n'
s += "#### PROPERTIES ####\n"
for property in self.properties:
s += indent(property.as_code(self.iid))
Expand All @@ -188,10 +188,10 @@ class Device(DataClassJsonMixin):

def as_code(self):
s = ""
s += f'"""'
s += '"""'
s += f"Support template for {self.description} ({self.type})\n\n"
s += f"Contains {len(self.services)} services\n"
s += f'"""\n\n'
s += '"""\n\n'

for serv in self.services:
s += serv.as_code()
Expand Down
44 changes: 42 additions & 2 deletions miio/gateway.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from datetime import datetime
from enum import IntEnum
from enum import Enum, IntEnum
from typing import Optional

import click

from .click_common import command, format_output
from .click_common import EnumType, command, format_output
from .device import Device
from .utils import brightness_and_color_to_int, int_to_brightness, int_to_rgb

Expand Down Expand Up @@ -34,12 +34,26 @@ class DeviceType(IntEnum):
SwitchOneChannel = 9
SensorHT = 10
Plug = 11
SensorSmoke = 15
AqaraHT = 19
SwitchLiveOneChannel = 20
SwitchLiveTwoChannels = 21
AqaraSwitch = 51
AqaraMotion = 52
AqaraMagnet = 53
AqaraRelayTwoChannels = 54
AqaraSqaureButton = 62
bskaplou marked this conversation as resolved.
Show resolved Hide resolved


class AqaraRelayToggleValue(Enum):
toggle = "toggle"
on = "on"
off = "off"


class AqaraRelayChannel(Enum):
first = "channel_0"
second = "channel_1"


class Gateway(Device):
Expand Down Expand Up @@ -139,6 +153,32 @@ def set_device_prop(self, sid, property, value):
"""Set the device property."""
return self.send("set_device_prop", {"sid": sid, property: value})

@command(
click.argument("sid"),
click.argument("channel", type=EnumType(AqaraRelayChannel)),
click.argument("value", type=EnumType(AqaraRelayToggleValue)),
)
def relay_toggle(self, sid, channel, value):
"""Toggle Aqara Wireless Relay 2ch"""
return self.send(
"toggle_ctrl_neutral",
[channel.value, value.value],
extra_parameters={"sid": sid},
)[0]

@command(
click.argument("sid"),
click.argument("channel", type=EnumType(AqaraRelayChannel)),
)
def relay_get_state(self, sid, channel):
"""Get the state of Aqara Wireless Relay 2ch for given sid"""
return self.send("get_device_prop_exp", [[sid, channel.value]])[0][0]

@command(click.argument("sid"))
def relay_get_load_power(self, sid):
"""Get the the load power of Aqara Wireless Relay 2ch for given sid"""
return self.send("get_device_prop_exp", [[sid, "load_power"]])[0][0]

@command()
def clock(self):
"""Alarm clock"""
Expand Down