Skip to content

Commit

Permalink
Unit tests of the Chuang Mi Plug V1 completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Nov 27, 2017
1 parent 5310663 commit dbe7cc7
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions miio/tests/test_plug_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,29 @@
class DummyPlugV1(PlugV1):
def __init__(self, *args, **kwargs):
self.state = {
'power': True,
'on': True,
'usb_on': True,
'temperature': 32,
}
self.return_values = {
'get_prop': self._get_state,
'set_on': lambda: self._set_state("power", True),
'set_off': lambda: self._set_state("power", False),
'set_usb_on': lambda: self._set_state("usb_on", True),
'set_usb_off': lambda: self._set_state("usb_on", False),
'set_on': lambda x: self._set_state("on", True),
'set_off': lambda x: self._set_state("on", False),
'set_usb_on': lambda x: self._set_state("usb_on", True),
'set_usb_off': lambda x: self._set_state("usb_on", False),
}
self.start_state = self.state.copy()

def send(self, command: str, parameters=None, retry_count=3):
"""Overridden send() to return values from `self.return_values`."""
if parameters is None:
return self.return_values[command]()

return self.return_values[command](parameters)

def _reset_state(self):
"""Revert back to the original state."""
self.state = self.start_state.copy()

def _set_state(self, var, value):
"""Set a state of a variable,
the value is expected to be an array with length of 1."""
# print("setting %s = %s" % (var, value))
"""Set a state of a variable"""
self.state[var] = value

def _get_state(self, props):
Expand Down

0 comments on commit dbe7cc7

Please sign in to comment.