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

gateway: add model property & implement SwitchOneChannel #722

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Changes from all 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
90 changes: 90 additions & 0 deletions miio/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ def discover_devices(self):
DeviceType.AqaraSwitchOneChannel: AqaraSwitchOneChannel,
DeviceType.AqaraSwitchTwoChannels: AqaraSwitchTwoChannels,
DeviceType.AqaraWallOutlet: AqaraWallOutlet,
DeviceType.Cube: Cube,
DeviceType.AqaraSquareButton: AqaraSquareButton,
DeviceType.SwitchOneChannel: SwitchOneChannel,
DeviceType.RemoteSwitchSingleV1: RemoteSwitchSingleV1,
DeviceType.RemoteSwitchSingle: RemoteSwitchSingle,
DeviceType.RemoteSwitchDouble: RemoteSwitchDouble,
}
devices_raw = self.get_prop("device_list")
self._devices = {}
Expand Down Expand Up @@ -605,6 +611,8 @@ class SubDevice:
these devices are connected through zigbee.
"""

_model = "unknown"

@attr.s(auto_attribs=True)
class props:
"""Defines properties of the specific device"""
Expand Down Expand Up @@ -639,6 +647,11 @@ def device_type(self):
"""Return the device type name."""
return self.type.name

@property
def model(self):
"""Return the device model."""
return self._model

@property
def firmware_version(self):
"""Return the firmware version."""
Expand Down Expand Up @@ -755,6 +768,7 @@ class AqaraHT(SubDevice):

accessor = "get_prop_sensor_ht"
properties = ["temperature", "humidity", "pressure"]
_model = "lumi.weather.v1"
rytilahti marked this conversation as resolved.
Show resolved Hide resolved

@attr.s(auto_attribs=True)
class props:
Expand Down Expand Up @@ -784,6 +798,7 @@ class SensorHT(SubDevice):

accessor = "get_prop_sensor_ht"
properties = ["temperature", "humidity", "pressure"]
_model = "unknown"

@attr.s(auto_attribs=True)
class props:
Expand Down Expand Up @@ -812,6 +827,7 @@ class AqaraMagnet(SubDevice):
"""Subdevice AqaraMagnet specific properties and methods"""

properties = ["unkown"]
_model = "lumi.sensor_magnet.aq2"

@attr.s(auto_attribs=True)
class props:
Expand All @@ -831,6 +847,7 @@ class AqaraPlug(SubDevice):

accessor = "get_prop_plug"
properties = ["power", "neutral_0", "load_power"]
_model = "unknown"

@attr.s(auto_attribs=True)
class props:
Expand All @@ -853,6 +870,7 @@ class AqaraRelayTwoChannels(SubDevice):
"""Subdevice AqaraRelayTwoChannels specific properties and methods"""

properties = ["load_power", "channel_0", "channel_1"]
_model = "unknown"

@attr.s(auto_attribs=True)
class props:
Expand Down Expand Up @@ -896,6 +914,7 @@ class AqaraSwitchOneChannel(SubDevice):
"""Subdevice AqaraSwitchOneChannel specific properties and methods"""

properties = ["neutral_0", "load_power"]
_model = "unknown"

@attr.s(auto_attribs=True)
class props:
Expand All @@ -916,6 +935,7 @@ class AqaraSwitchTwoChannels(SubDevice):
"""Subdevice AqaraSwitchTwoChannels specific properties and methods"""

properties = ["neutral_0", "neutral_1", "load_power"]
_model = "unknown"

@attr.s(auto_attribs=True)
class props:
Expand All @@ -938,6 +958,7 @@ class AqaraWallOutlet(SubDevice):
"""Subdevice AqaraWallOutlet specific properties and methods"""

properties = ["channel_0", "load_power"]
_model = "lumi.ctrl_86plug.aq1"

@attr.s(auto_attribs=True)
class props:
Expand Down Expand Up @@ -967,3 +988,72 @@ def on(self):
def off(self):
"""Turn off Aqara Wall Outlet"""
return self.send_arg("toggle_plug", ["channel_0", "off"]).pop()


class Cube(SubDevice):
"""Subdevice Cube specific properties and methods"""

properties = []
_model = "lumi.sensor_cube.v1"


class AqaraSquareButton(SubDevice):
"""Subdevice AqaraSquareButton specific properties and methods"""

properties = []
_model = "lumi.sensor_switch.aq3"


class SwitchOneChannel(SubDevice):
"""Subdevice SwitchOneChannel specific properties and methods"""

properties = ["neutral_0"]
_model = "lumi.ctrl_neutral1.v1"

@attr.s(auto_attribs=True)
class props:
"""Device specific properties"""

status: str = None # 'on' / 'off'

@command()
def update(self):
"""Update all device properties"""
values = self.get_property_exp(self.properties)
self._props.status = values[0]

@command()
def toggle(self):
"""Toggle Switch One Channel"""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "toggle"]).pop()

@command()
def on(self):
"""Turn on Switch One Channel"""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "on"]).pop()

@command()
def off(self):
"""Turn off Switch One Channel"""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "off"]).pop()


class RemoteSwitchSingleV1(SubDevice):
"""Subdevice RemoteSwitchSingleV1 specific properties and methods"""

properties = []
_model = "lumi.sensor_86sw1.v1"


class RemoteSwitchSingle(SubDevice):
"""Subdevice RemoteSwitchSingle specific properties and methods"""

properties = []
_model = "lumi.remote.b186acn01"


class RemoteSwitchDouble(SubDevice):
"""Subdevice RemoteSwitchDouble specific properties and methods"""

properties = []
_model = "lumi.remote.b286acn01"