Skip to content

Commit

Permalink
Added support of Aqara Wireless Relay 2ch (LLKZMK11LM) (rytilahti#696)
Browse files Browse the repository at this point in the history
* Added support of Aqara Wireless Relay 2ch (LLKZMK11LM)

* format

* removed f in strings with no subs

* isort fixing

* Update miio/gateway.py

Co-authored-by: Teemu R. <tpr@iki.fi>

Co-authored-by: Teemu R. <tpr@iki.fi>
  • Loading branch information
2 people authored and xvlady committed May 9, 2021
1 parent f21223a commit 4886c14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
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
AqaraSquareButton = 62


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

0 comments on commit 4886c14

Please sign in to comment.