Skip to content

Commit 89efe6e

Browse files
committed
Update temperature when changing to auto mode
Use the weekly programme to retrieve current temperature when changing to automatic mode.
1 parent 3315f38 commit 89efe6e

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

maxcube/cube.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ def set_temperature_mode(self, thermostat, temperature, mode):
283283
thermostat.mode = mode
284284
if temperature > 0:
285285
thermostat.target_temperature = int(temperature * 2) / 2.0
286+
elif mode == MAX_DEVICE_MODE_AUTOMATIC:
287+
thermostat.target_temperature = thermostat.get_current_temp_in_auto_mode()
286288
return True
287289
return False
288290

maxcube/thermostat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from maxcube.device import MaxDevice
2+
from time import localtime
3+
from typing import Dict, List
24

5+
PROG_DAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
36

47
class MaxThermostat(MaxDevice):
58
def __init__(self):
@@ -12,3 +15,13 @@ def __init__(self):
1215
self.target_temperature = None
1316
self.actual_temperature = None
1417
self.mode = None
18+
self.programme: Dict[str, List[Dict[str, int]]] = {}
19+
20+
def get_current_temp_in_auto_mode(self):
21+
t = localtime()
22+
weekday = PROG_DAYS[t.tm_wday]
23+
time = f"{t.tm_hour:02}:{t.tm_min:02}"
24+
for point in self.programme.get(weekday, []):
25+
if time < point['until']:
26+
return point['temp']
27+
return None

tests/test_cube.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from time import strptime
12
from typing import List
23
from unittest import TestCase
34
from unittest.mock import MagicMock, call, patch
@@ -16,6 +17,8 @@
1617
MAX_DEVICE_MODE_BOOST
1718
from maxcube.room import MaxRoom
1819

20+
import maxcube.thermostat
21+
1922
def to_messages(lines):
2023
return [ Message.decode(line) for line in lines]
2124

@@ -397,3 +400,16 @@ def test_get_device_as_dict(self, ClassMock):
397400
{'until': '24:00', 'temp': 8}
398401
]
399402
)
403+
404+
@patch('maxcube.thermostat.localtime')
405+
def test_set_auto_mode_read_temp_from_program(self, localtime_mock, ClassMock):
406+
localtime_mock.return_value = strptime("2012-10-22T05:30", "%Y-%m-%dT%H:%M")
407+
print(localtime_mock.return_value)
408+
self.init(ClassMock, INIT_RESPONSE_2)
409+
device = self.cube.devices[0]
410+
self.assertEqual(8.0, device.target_temperature)
411+
self.cube.set_mode(device, MAX_DEVICE_MODE_AUTOMATIC)
412+
self.assertEqual(21.0, device.target_temperature)
413+
self.assertEqual(MAX_DEVICE_MODE_AUTOMATIC, device.mode)
414+
self.commander.send_radio_msg.assert_called_once()
415+
self.commander.send_radio_msg.assert_called_with('0004400000000E2EBA0100')

tests/test_thermostat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from unittest import TestCase
3+
from maxcube.thermostat import MaxThermostat
4+
5+
class TestMessage(TestCase):
6+
""" Test Max! thermostat """
7+
8+
def testGetCurrentTemperatureReturnsNoneIfUninitialized(self):
9+
t = MaxThermostat()
10+
self.assertIsNone(t.get_current_temp_in_auto_mode())

0 commit comments

Comments
 (0)