-
-
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
Load power of the PowerStrip fixed and removed from the Plug #117
Changes from 3 commits
47d59ac
44358b7
ebac318
1c09337
537b655
921bb71
024c147
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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', | ||
'temperature': 32, | ||
'current': 123, | ||
'power_consume_rate': 123, | ||
} | ||
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"] | ||
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 (81 > 79 characters) 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 (81 > 79 characters) |
||
assert self.state().load_power == self.device.start_state["power_consume_rate"] | ||
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 (87 > 79 characters) 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 (87 > 79 characters) 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 (87 > 79 characters) |
||
|
||
def test_status_without_power_consume_rate(self): | ||
del self.device.state["power_consume_rate"] | ||
|
||
assert self.state().load_power is None |
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 (81 > 79 characters)