Skip to content

Commit

Permalink
Unit tests updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Feb 26, 2018
1 parent 2211ee7 commit 1db504a
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion miio/tests/test_airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
SwingMode, STORAGE_SLOT_ID
import pytest

STATE_ON = ['on']
STATE_OFF = ['off']

class DummyAirConditioningCompanion(AirConditioningCompanion):
def __init__(self, *args, **kwargs):
Expand All @@ -17,6 +19,7 @@ def __init__(self, *args, **kwargs):
'get_ir_learn_result': lambda x: True,
'send_ir_code': lambda x: True,
'send_cmd': self._send_cmd_input_validation,
'set_power': lambda x: self._set_power(x),
}
self.start_state = self.state.copy()

Expand All @@ -32,6 +35,14 @@ def _get_state(self, props):
"""Return the requested data"""
return self.state

def _set_power(self, value: str):
"""Set the requested power state"""
if value == STATE_ON:
self.state[1] = self.state[1][:2] + '1' + self.state[1][3:]

if value == STATE_OFF:
self.state[1] = self.state[1][:2] + '0' + self.state[1][3:]

def _send_cmd_input_validation(self, props):
return all(c in string.hexdigits for c in props[0])

Expand All @@ -50,11 +61,25 @@ def is_on(self):
def state(self):
return self.device.status()

def test_on(self):
self.device.off() # ensure off
assert self.is_on() 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 False
assert self.state().air_condition_power == '2'
assert self.state().load_power == 2
assert self.state().air_condition_model == '0180222221'
assert self.state().temperature == 25
assert self.state().swing_mode is False
Expand Down

0 comments on commit 1db504a

Please sign in to comment.