Skip to content

Commit

Permalink
Chuangmi V1 and V3 merge completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Mar 16, 2018
1 parent e56d0b7 commit b2e3965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions miio/chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def temperature(self) -> int:
@property
def load_power(self) -> Optional[int]:
"""Current power load, if available."""
if self.data["load_power"] is not None:
if "load_power" in self.data and self.data["load_power"] is not None:
return self.data["load_power"]
return None

@property
def wifi_led(self) -> Optional[bool]:
"""True if the wifi led is turned on."""
if self.data["wifi_led"] is not None:
if "wifi_led" in self.data and self.data["wifi_led"] is not None:
return self.data["wifi_led"] == "on"
return None

Expand Down Expand Up @@ -100,10 +100,16 @@ def status(self) -> ChuangmiPlugStatus:

def on(self):
"""Power on."""
if self.model == MODEL_CHUANGMI_PLUG_V3:
return self.send("set_power", ["on"])

return self.send("set_on", [])

def off(self):
"""Power off."""
if self.model == MODEL_CHUANGMI_PLUG_V3:
return self.send("set_power", ["off"])

return self.send("set_off", [])

def usb_on(self):
Expand Down
4 changes: 2 additions & 2 deletions miio/tests/test_chuangmi_plug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase
from miio import ChuangmiPlug
from miio.chuangmi_plug import (ChuangmiPlugV1Status, MODEL_CHUANGMI_PLUG_V1,
from miio.chuangmi_plug import (ChuangmiPlugStatus, MODEL_CHUANGMI_PLUG_V1,
MODEL_CHUANGMI_PLUG_V3, )
from .dummies import DummyDevice
import pytest
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_status(self):
start_state_extended = self.device.start_state.copy()
start_state_extended['load_power'] = load_power
assert repr(self.state()) == repr(
ChuangmiPlugV3Status(start_state_extended))
ChuangmiPlugStatus(start_state_extended))

assert self.is_on() is True
assert self.state().usb_power is True
Expand Down

0 comments on commit b2e3965

Please sign in to comment.