-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
Xiaomi Power Strip V1 is unable to handle some V2 properties #303
Merged
syssi
merged 5 commits into
rytilahti:master
from
syssi:feature/powerstrip-v1-properties
Apr 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3528681
Xiaomi Power Strip V1 is unable to handle the new properties (Closes:…
syssi 658ff22
Indents fixed
syssi ba638c6
Discovery of the different power strips updated
syssi 9d5e2ab
Tests added
syssi 0df1f92
Supported properties verified and properly assigned
syssi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,17 @@ | |
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
MODEL_POWER_STRIP_V1 = 'qmi.powerstrip.v1' | ||
MODEL_POWER_STRIP_V2 = 'zimi.powerstrip.v2' | ||
|
||
AVAILABLE_PROPERTIES = { | ||
MODEL_POWER_STRIP_V1: ['power', 'temperature', 'current', 'mode', | ||
'power_consume_rate'], | ||
MODEL_POWER_STRIP_V2: ['power', 'temperature', 'current', 'mode', | ||
'power_consume_rate', 'wifi_led', 'power_price', | ||
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. continuation line under-indented for visual indent |
||
'voltage', 'power_factor', 'elec_leakage'], | ||
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. continuation line under-indented for visual indent |
||
} | ||
|
||
|
||
class PowerStripException(DeviceException): | ||
pass | ||
|
@@ -70,9 +81,11 @@ def mode(self) -> Optional[PowerMode]: | |
return None | ||
|
||
@property | ||
def wifi_led(self) -> bool: | ||
def wifi_led(self) -> Optional[bool]: | ||
"""True if the wifi led is turned on.""" | ||
return self.data["wifi_led"] == "on" | ||
if self.data["wifi_led"] is not None: | ||
return self.data["wifi_led"] == "on" | ||
return None | ||
|
||
@property | ||
def power_price(self) -> Optional[int]: | ||
|
@@ -132,6 +145,16 @@ def __json__(self): | |
class PowerStrip(Device): | ||
"""Main class representing the smart power strip.""" | ||
|
||
def __init__(self, ip: str = None, token: str = None, start_id: int = 0, | ||
debug: int = 0, lazy_discover: bool = True, | ||
model: str = MODEL_POWER_STRIP_V1) -> None: | ||
super().__init__(ip, token, start_id, debug, lazy_discover) | ||
|
||
if model in AVAILABLE_PROPERTIES: | ||
self.model = model | ||
else: | ||
self.model = MODEL_POWER_STRIP_V1 | ||
|
||
@command( | ||
default_output=format_output( | ||
"", | ||
|
@@ -148,9 +171,7 @@ class PowerStrip(Device): | |
) | ||
def status(self) -> PowerStripStatus: | ||
"""Retrieve properties.""" | ||
properties = ['power', 'temperature', 'current', 'mode', | ||
'power_consume_rate', 'wifi_led', 'power_price', | ||
'voltage', 'power_factor', 'elec_leakage'] | ||
properties = AVAILABLE_PROPERTIES[self.model] | ||
values = self.send( | ||
"get_prop", | ||
properties | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
continuation line under-indented for visual indent