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 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
62 changes: 62 additions & 0 deletions mirobo/strip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from .device import Device
from typing import Any, Dict


class Strip(Device):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

"""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: str):
"""Set mode."""
Copy link
Owner

Choose a reason for hiding this comment

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

What kind of modes are accepted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"green" (aka eco) and "normal".

Copy link
Owner

Choose a reason for hiding this comment

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

Ok. Would it be worth expose this as an enum too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could you provide an example? I'm confused.

Copy link
Owner

Choose a reason for hiding this comment

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

For example something like this:

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

and calling set_power_mode(PowerMode.Eco)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it! This is nice. I will update the PRs asap.

Copy link
Owner

Choose a reason for hiding this comment

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

Btw, you can then simply use mode.value to get the value on the right hand side insie set_mode(), and other way around when reading it, PowerMode('green') will give you back the PowerMode.Eco :-)


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


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

Choose a reason for hiding this comment

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

undefined name 'Dict'
undefined name 'Any'

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) -> float:
return 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