-
-
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 smart wifi socket added #29
Changes from 7 commits
311537d
cea4e70
e243faa
bea60f6
8c34d51
e331b9d
c8777c6
7b0829b
df9f45d
18f3c7e
401dee4
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 |
---|---|---|
|
@@ -39,6 +39,34 @@ def pretty_time(x: int) -> datetime: | |
} | ||
|
||
|
||
class PlugStatus: | ||
"""Container for status reports from the plug.""" | ||
def __init__(self, data: Dict[str, Any]) -> None: | ||
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"] | ||
|
||
def __str__(self) -> str: | ||
s = "<PlugStatus power=%s, temperature=%s, current=%s>" % (self.state, | ||
self.temperature, | ||
self.current) | ||
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. line too long (80 > 79 characters) |
||
return s | ||
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 think:
Properly intended would look nicer, but this is fine too. |
||
|
||
|
||
class VacuumStatus: | ||
"""Container for status reports from the vacuum.""" | ||
def __init__(self, data: Dict[str, Any]) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from .device import Device | ||
from .containers import PlugStatus | ||
|
||
|
||
class Plug(Device): | ||
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. expected 2 blank lines, found 1 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. expected 2 blank lines, found 1 |
||
"""Main class representing the smart wifi socket / plug.""" | ||
|
||
def start(self): | ||
"""Power on.""" | ||
return self.send("set_power", ["on"]) | ||
|
||
def stop(self): | ||
"""Power off.""" | ||
return self.send("set_power", ["off"]) | ||
|
||
def status(self): | ||
"""Retrieve properties.""" | ||
properties = ['power', 'temperature', 'current'] | ||
values = self.send( | ||
"get_prop", | ||
properties | ||
) | ||
return PlugStatus(dict(zip(properties, values))) |
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.
line too long (84 > 79 characters)