Skip to content

Commit

Permalink
Device support for the xiaomi power strip added. (#32)
Browse files Browse the repository at this point in the history
* Device support for the xiaomi power strip added.

* Strip added to __init__.

* Status class moved.

* Missing import added.

* Response example added.
PowerMode class introduced.

* Missing return added.

* PowerMode class moved.

* Code reformatted.
  • Loading branch information
syssi authored and rytilahti committed Jul 25, 2017
1 parent bef8fc4 commit a28fab5
Show file tree
Hide file tree
Showing 2 changed files with 72 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,4 +3,5 @@
from mirobo.containers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer
from mirobo.vacuum import Vacuum, VacuumException
from mirobo.plug import Plug
from mirobo.strip import Strip
from mirobo.device import Device, DeviceException
71 changes: 71 additions & 0 deletions mirobo/strip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from .device import Device
from typing import Any, Dict
import enum


class PowerMode(enum.Enum):
Eco = 'green'
Normal = 'normal'


class Strip(Device):
"""Main class representing the smart strip."""

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

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

def status(self):
"""Retrieve properties."""
properties = ['power', 'temperature', 'current', 'mode']
values = self.send(
"get_prop",
properties
)
return StripStatus(dict(zip(properties, values)))

def set_power_mode(self, mode: PowerMode):
"""Set mode."""

# green, normal
return self.send("set_power_mode", [mode.value])


class StripStatus:
"""Container for status reports from the strip."""

def __init__(self, data: Dict[str, Any]) -> None:
# {'power': 'on', 'temperature': 48.11,
# 'current': 0.06, 'mode': 'green'}
self.data = data

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

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

@property
def temperature(self) -> float:
return self.data["temperature"]

@property
def current(self) -> float:
return self.data["current"]

@property
def mode(self) -> PowerMode:
return PowerMode(self.data["mode"])

def __str__(self) -> str:
s = "<StripStatus power=%s, temperature=%s, " \
"current=%s mode=%s>" % \
(self.power, self.temperature,
self.current, self.mode)
return s

0 comments on commit a28fab5

Please sign in to comment.