diff --git a/maxcube/cube.py b/maxcube/cube.py index 19ae4ad..3f0c938 100644 --- a/maxcube/cube.py +++ b/maxcube/cube.py @@ -283,6 +283,8 @@ def set_temperature_mode(self, thermostat, temperature, mode): thermostat.mode = mode if temperature > 0: thermostat.target_temperature = int(temperature * 2) / 2.0 + elif mode == MAX_DEVICE_MODE_AUTOMATIC: + thermostat.target_temperature = thermostat.get_current_temp_in_auto_mode() return True return False diff --git a/maxcube/thermostat.py b/maxcube/thermostat.py index 49c738c..5167c1a 100644 --- a/maxcube/thermostat.py +++ b/maxcube/thermostat.py @@ -1,5 +1,8 @@ from maxcube.device import MaxDevice +from time import localtime +from typing import Dict, List +PROG_DAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] class MaxThermostat(MaxDevice): def __init__(self): @@ -12,3 +15,13 @@ def __init__(self): self.target_temperature = None self.actual_temperature = None self.mode = None + self.programme: Dict[str, List[Dict[str, int]]] = {} + + def get_current_temp_in_auto_mode(self): + t = localtime() + weekday = PROG_DAYS[t.tm_wday] + time = f"{t.tm_hour:02}:{t.tm_min:02}" + for point in self.programme.get(weekday, []): + if time < point['until']: + return point['temp'] + return None diff --git a/tests/test_cube.py b/tests/test_cube.py index 6b78648..0efc784 100644 --- a/tests/test_cube.py +++ b/tests/test_cube.py @@ -1,3 +1,4 @@ +from time import strptime from typing import List from unittest import TestCase from unittest.mock import MagicMock, call, patch @@ -16,6 +17,8 @@ MAX_DEVICE_MODE_BOOST from maxcube.room import MaxRoom +import maxcube.thermostat + def to_messages(lines): return [ Message.decode(line) for line in lines] @@ -397,3 +400,16 @@ def test_get_device_as_dict(self, ClassMock): {'until': '24:00', 'temp': 8} ] ) + + @patch('maxcube.thermostat.localtime') + def test_set_auto_mode_read_temp_from_program(self, localtime_mock, ClassMock): + localtime_mock.return_value = strptime("2012-10-22T05:30", "%Y-%m-%dT%H:%M") + print(localtime_mock.return_value) + self.init(ClassMock, INIT_RESPONSE_2) + device = self.cube.devices[0] + self.assertEqual(8.0, device.target_temperature) + self.cube.set_mode(device, MAX_DEVICE_MODE_AUTOMATIC) + self.assertEqual(21.0, device.target_temperature) + self.assertEqual(MAX_DEVICE_MODE_AUTOMATIC, device.mode) + self.commander.send_radio_msg.assert_called_once() + self.commander.send_radio_msg.assert_called_with('0004400000000E2EBA0100') diff --git a/tests/test_thermostat.py b/tests/test_thermostat.py new file mode 100644 index 0000000..067e7a5 --- /dev/null +++ b/tests/test_thermostat.py @@ -0,0 +1,10 @@ + +from unittest import TestCase +from maxcube.thermostat import MaxThermostat + +class TestMessage(TestCase): + """ Test Max! thermostat """ + + def testGetCurrentTemperatureReturnsNoneIfUninitialized(self): + t = MaxThermostat() + self.assertIsNone(t.get_current_temp_in_auto_mode())