-
-
Notifications
You must be signed in to change notification settings - Fork 563
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 all 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,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): | ||
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 'PowerMode' 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 don't understand the complain. :-( 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. 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: | ||
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 '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 |
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.
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 comment
The 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 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.