-
-
Notifications
You must be signed in to change notification settings - Fork 567
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
Changes from 4 commits
e3bd22a
0178c1b
44d9db8
610ff31
682e4d4
8f72298
e8dbf26
eecaf6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
"""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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will care about. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of modes are accepted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "green" (aka eco) and "normal". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Would it be worth expose this as an enum too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you provide an example? I'm confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example something like this:
and calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! This is nice. I will update the PRs asap. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undefined name 'Dict' |
||
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 |
There was a problem hiding this comment.
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