-
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load power of the PowerStrip fixed and removed from the Plug (#117)
* Property load_power removed from the plug. It's a feature of the PowerStrip. The Xiaomi plug doesn't provide load. Load power workaround of the PowerStrip replaced by a property called "power_consume_rate" which provides the same values as the android app. * Line too long fixed. * Unittest for the PowerStrip added. Unittest of the Plug updated. * Fixture updated. * Fixture updated. Missing property ("mode") added. * Make hound happy again. * The hound error is fine for better readability of the assertion.
- Loading branch information
Showing
4 changed files
with
72 additions
and
26 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from unittest import TestCase | ||
from miio import PowerStrip | ||
from .dummies import DummyDevice | ||
import pytest | ||
|
||
|
||
class DummyPowerStrip(DummyDevice, PowerStrip): | ||
def __init__(self, *args, **kwargs): | ||
self.state = { | ||
'power': 'on', | ||
'mode': 'normal', | ||
'temperature': 32.5, | ||
'current': 123, | ||
'power_consume_rate': 12.5, | ||
} | ||
self.return_values = { | ||
'get_prop': self._get_state, | ||
'set_power': lambda x: self._set_state("power", x), | ||
} | ||
super().__init__(args, kwargs) | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def powerstrip(request): | ||
request.cls.device = DummyPowerStrip() | ||
# TODO add ability to test on a real device | ||
|
||
|
||
@pytest.mark.usefixtures("powerstrip") | ||
class TestPowerStrip(TestCase): | ||
def is_on(self): | ||
return self.device.status().is_on | ||
|
||
def state(self): | ||
return self.device.status() | ||
|
||
def test_on(self): | ||
self.device.off() # ensure off | ||
|
||
start_state = self.is_on() | ||
assert start_state is False | ||
|
||
self.device.on() | ||
assert self.is_on() is True | ||
|
||
def test_off(self): | ||
self.device.on() # ensure on | ||
|
||
assert self.is_on() is True | ||
self.device.off() | ||
assert self.is_on() is False | ||
|
||
def test_status(self): | ||
self.device._reset_state() | ||
|
||
assert self.is_on() is True | ||
assert self.state().temperature == self.device.start_state["temperature"] | ||
assert self.state().load_power == self.device.start_state["power_consume_rate"] | ||
|
||
def test_status_without_power_consume_rate(self): | ||
del self.device.state["power_consume_rate"] | ||
|
||
assert self.state().load_power is None |