Skip to content

Commit

Permalink
Use new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Mar 31, 2018
1 parent 2885f92 commit 1b66cce
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions miio/chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from collections import defaultdict
from .device import Device
from .utils import deprecated
from .click_common import (
DeviceGroupMeta, device_command, echo_return_status
)
from .click_common import command, format_output

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,8 +86,11 @@ def __repr__(self) -> str:
self.wifi_led)
return s

def __json__(self):
return self.data

class ChuangmiPlug(Device, metaclass=DeviceGroupMeta):

class ChuangmiPlug(Device):
"""Main class representing the Chuangmi Plug V1 and V3."""

def __init__(self, ip: str = None, token: str = None, start_id: int = 0,
Expand All @@ -102,14 +103,15 @@ def __init__(self, ip: str = None, token: str = None, start_id: int = 0,
else:
self.model = MODEL_CHUANGMI_PLUG_M1

@device_command(
echo_return_status("",
"Power: {result.power}\n"
"USB Power: {result.usb_power}\n"
"Temperature: {result.temperature} °C\n"
"Load power: {result.load_power}\n"
"WiFi LED: {result.wifi_led}")
)
@command(
default_output=format_output(
"",
"Power: {result.power}\n"
"USB Power: {result.usb_power}\n"
"Temperature: {result.temperature} °C\n"
"Load power: {result.load_power}\n"
"WiFi LED: {result.wifi_led}\n")
)
def status(self) -> ChuangmiPlugStatus:
"""Retrieve properties."""
properties = AVAILABLE_PROPERTIES[self.model]
Expand All @@ -135,35 +137,43 @@ def status(self) -> ChuangmiPlugStatus:
return ChuangmiPlugStatus(
defaultdict(lambda: None, zip(properties, values)))

@device_command(echo_return_status("Powering on"))
@command(
default_output = format_output("Powering on"),
)
def on(self):
"""Power on."""
if self.model == MODEL_CHUANGMI_PLUG_V1:
return self.send("set_on", [])

return self.send("set_power", ["on"])

@device_command(echo_return_status("Powering off"))
@command(
default_output = format_output("Powering off"),
)
def off(self):
"""Power off."""
if self.model == MODEL_CHUANGMI_PLUG_V1:
return self.send("set_off", [])

return self.send("set_power", ["off"])

@device_command(echo_return_status("Powering USB on"))
@command(
default_output = format_output("Powering USB on"),
)
def usb_on(self):
"""Power on."""
return self.send("set_usb_on", [])

@device_command(echo_return_status("Powering USB off"))
@command(
default_output = format_output("Powering USB off"),
)
def usb_off(self):
"""Power off."""
return self.send("set_usb_off", [])

@device_command(
@command(
click.argument("wifi_led", type=bool),
echo_return_status(
default_output=format_output(
lambda wifi_led: "Turning on WiFi LED"
if wifi_led else "Turning off WiFi LED"
)
Expand Down

0 comments on commit 1b66cce

Please sign in to comment.