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

Xiaomi Power Strip V1 is unable to handle some V2 properties #303

Merged
merged 5 commits into from
Apr 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions miio/powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

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

MODEL_POWER_STRIP_V2: ['power', 'temperature', 'current', 'mode',
'power_consume_rate', 'wifi_led', 'power_price',

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

'voltage', 'power_factor', 'elec_leakage'],

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

}


class PowerStripException(DeviceException):
pass
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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(
"",
Expand All @@ -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
Expand Down