-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_thermostat.py
60 lines (44 loc) · 1.8 KB
/
test_thermostat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from unittest.mock import Mock
import pytest
from elkm1_lib.const import ThermostatFan, ThermostatMode, ThermostatSetting
from elkm1_lib.message import MessageEncode
from elkm1_lib.thermostats import Thermostat, Thermostats
from .util import rx_msg
@pytest.fixture
def thermostats(notifier):
return Thermostats(Mock(), notifier)
def test_entry_exit_general(thermostats, notifier):
rx_msg("TR", "0120072687500", notifier)
thermostat = thermostats[0]
assert thermostat.mode == ThermostatMode.COOL
assert thermostat.hold is False
assert thermostat.fan == ThermostatFan.AUTO
assert thermostat.current_temp == 72
assert thermostat.heat_setpoint == 68
assert thermostat.cool_setpoint == 75
assert thermostat.humidity == 0
def test_thermostat_set_types_are_correct(notifier):
thermostat = Thermostat(0, Mock(), notifier)
with pytest.raises(ValueError):
thermostat.set(ThermostatSetting.MODE, 3)
with pytest.raises(ValueError):
thermostat.set(ThermostatSetting.COOL_SETPOINT, True)
def test_thermostat_set_sends_correct_command_to_elk():
mock = Mock()
thermostat = Thermostat(0, mock, Mock())
thermostat.set(ThermostatSetting.MODE, ThermostatMode.COOL)
mock.send.assert_called_with(
MessageEncode(message="0Bts0102000", response_command=None)
)
thermostat.set(ThermostatSetting.HOLD, True)
mock.send.assert_called_with(
MessageEncode(message="0Bts0101100", response_command=None)
)
thermostat.set(ThermostatSetting.FAN, ThermostatFan.AUTO)
mock.send.assert_called_with(
MessageEncode(message="0Bts0100200", response_command=None)
)
thermostat.set(ThermostatSetting.HEAT_SETPOINT, 42)
mock.send.assert_called_with(
MessageEncode(message="0Bts0142500", response_command=None)
)