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

Unit tests of the Xiaomi Power Strip extended #136

Merged
merged 4 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions miio/powerstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def temperature(self) -> float:
"""Current temperature."""
return self.data["temperature"]

@property
def current(self) -> Optional[float]:
"""Current, if available. Meaning and voltage reference unknown."""
if self.data["current"] is not None:
return self.data["current"]
return None

@property
def load_power(self) -> Optional[float]:
"""Current power load, if available."""
Expand Down
16 changes: 15 additions & 1 deletion miio/tests/test_powerstrip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestCase
from miio import PowerStrip
from miio.powerstrip import PowerMode
from .dummies import DummyDevice
import pytest

Expand All @@ -10,12 +11,13 @@ def __init__(self, *args, **kwargs):
'power': 'on',
'mode': 'normal',
'temperature': 32.5,
'current': 123,
'current': 25.5,
'power_consume_rate': 12.5,
}
self.return_values = {
'get_prop': self._get_state,
'set_power': lambda x: self._set_state("power", x),
'set_power_mode': lambda x: self._set_state("mode", x),
}
super().__init__(args, kwargs)

Expand Down Expand Up @@ -54,10 +56,22 @@ def test_status(self):
self.device._reset_state()

assert self.is_on() is True
assert self.state().mode == PowerMode(self.device.start_state["mode"])
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"]

def test_status_without_power_consume_rate(self):
del self.device.state["power_consume_rate"]

assert self.state().load_power is None

def test_set_power_mode(self):
def mode():
return self.device.status().mode

self.device.set_power_mode(PowerMode.Eco)
assert mode() == PowerMode.Eco
self.device.set_power_mode(PowerMode.Normal)
assert mode() == PowerMode.Normal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file