Skip to content

Commit

Permalink
Supported properties verified and properly assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Apr 8, 2018
1 parent 9d5e2ab commit 0df1f92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions miio/powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
'temperature',
'current',
'mode',
'power_consume_rate'
'power_consume_rate',
'voltage',
'power_factor',
'elec_leakage',
],
MODEL_POWER_STRIP_V2: [
'power',
Expand All @@ -29,9 +32,6 @@
'power_consume_rate',
'wifi_led',
'power_price',
'voltage',
'power_factor',
'elec_leakage'
],
}

Expand Down Expand Up @@ -116,10 +116,10 @@ def leakage_current(self) -> Optional[int]:
return None

@property
def voltage(self) -> Optional[int]:
def voltage(self) -> Optional[float]:
"""The voltage, if available."""
if "voltage" in self.data and self.data["voltage"] is not None:
return self.data["voltage"]
return self.data["voltage"] / 100.0
return None

@property
Expand Down
18 changes: 9 additions & 9 deletions miio/tests/test_powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, *args, **kwargs):
'temperature': 32.5,
'current': 25.5,
'power_consume_rate': 12.5,
'voltage': 23057,
'power_factor': 12,
'elec_leakage': 8,
}
self.return_values = {
'get_prop': self._get_state,
Expand Down Expand Up @@ -64,9 +67,9 @@ def test_status(self):
assert self.state().temperature == self.device.start_state["temperature"]
assert self.state().current == self.device.start_state["current"]
assert self.state().load_power == self.device.start_state["power_consume_rate"]
assert self.state().voltage is None
assert self.state().power_factor is None
assert self.state().leakage_current is None
assert self.state().voltage == self.device.start_state["voltage"] / 100.0
assert self.state().power_factor == self.device.start_state["power_factor"]
assert self.state().leakage_current == self.device.start_state["elec_leakage"]

def test_status_without_power_consume_rate(self):
self.device._reset_state()
Expand Down Expand Up @@ -108,9 +111,6 @@ def __init__(self, *args, **kwargs):
'power_consume_rate': 12.5,
'wifi_led': 'off',
'power_price': 49,
'voltage': 230,
'elec_leakage': 0,
'power_factor': 0.5,
}
self.return_values = {
'get_prop': self._get_state,
Expand Down Expand Up @@ -161,9 +161,9 @@ def test_status(self):
assert self.state().temperature == self.device.start_state["temperature"]
assert self.state().current == self.device.start_state["current"]
assert self.state().load_power == self.device.start_state["power_consume_rate"]
assert self.state().voltage == self.device.start_state["voltage"]
assert self.state().power_factor == self.device.start_state["power_factor"]
assert self.state().leakage_current == self.device.start_state["elec_leakage"]
assert self.state().voltage is None
assert self.state().power_factor is None
assert self.state().leakage_current is None

def test_status_without_power_consume_rate(self):
self.device._reset_state()
Expand Down

0 comments on commit 0df1f92

Please sign in to comment.