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

Device support for the xiaomi power strip added. #32

Merged
merged 8 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
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
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']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example response? It would be nice to be added either here or into the Status class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will care about.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! (I saw this was added, but the "todo" is still open.

values = self.send(
"get_prop",
properties
)
return StripStatus(dict(zip(properties, values)))

def set_power_mode(self, mode: PowerMode):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'PowerMode'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the complain. :-(

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PowerMode is being used before it has been defined (see my comment in another PR :))

"""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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name '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