Skip to content

Commit

Permalink
Unit tests of the Xiaomi Power Strip extended. (#136)
Browse files Browse the repository at this point in the history
* Property "current" re-introduced for completeness.
  • Loading branch information
syssi authored Nov 28, 2017
1 parent 90f0d8b commit 4832974
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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
30 changes: 28 additions & 2 deletions 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,34 @@ 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"]
self.device._reset_state()

self.device.state["power_consume_rate"] = None
assert self.state().load_power is None

def test_status_without_current(self):
self.device._reset_state()

self.device.state["current"] = None
assert self.state().current is None

def test_status_without_mode(self):
self.device._reset_state()

self.device.state["mode"] = None
assert self.state().mode 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

0 comments on commit 4832974

Please sign in to comment.