Skip to content

Commit

Permalink
Device support for the chuangmi plug v1 added (#33)
Browse files Browse the repository at this point in the history
* Device support for the chuangmi plug v1 strip added.

* Status class moved.

* Missing import added.
  • Loading branch information
syssi authored and rytilahti committed Aug 14, 2017
1 parent 42a9d9b commit 2e3039b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions mirobo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mirobo.vacuumcontainers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer
from mirobo.vacuum import Vacuum, VacuumException
from mirobo.plug import Plug
from mirobo.plug_v1 import PlugV1
from mirobo.airpurifier import AirPurifier
from mirobo.strip import Strip
from mirobo.device import Device, DeviceException
55 changes: 55 additions & 0 deletions mirobo/plug_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from .device import Device
from typing import Any, Dict


class PlugV1(Device):
"""Main class representing the chuangmi plug v1."""

def on(self):
"""Power on."""
return self.send("set_on", [])

def off(self):
"""Power off."""
return self.send("set_off", [])

def usb_on(self):
"""Power on."""
return self.send("set_usb_on", [])

def usb_off(self):
"""Power off."""
return self.send("set_usb_off", [])

def status(self):
"""Retrieve properties."""
properties = ['on', 'usb_on']
values = self.send(
"get_prop",
properties
)
return PlugV1Status(dict(zip(properties, values)))


class PlugV1Status:
"""Container for status reports from the plug."""
def __init__(self, data: Dict[str, Any]) -> None:
self.data = data

@property
def power(self) -> bool:
return self.data["on"]

@property
def is_on(self) -> bool:
return self.power

@property
def usb_power(self) -> bool:
return self.data["usb_on"]

def __str__(self) -> str:
s = "<PlugV1Status power=%s, usb_power=%s>" % \
(self.power,
self.usb_power)
return s

0 comments on commit 2e3039b

Please sign in to comment.