Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions maxcube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions maxcube/thermostat.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
16 changes: 16 additions & 0 deletions tests/test_cube.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import strptime
from typing import List
from unittest import TestCase
from unittest.mock import MagicMock, call, patch
Expand All @@ -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]

Expand Down Expand Up @@ -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')
10 changes: 10 additions & 0 deletions tests/test_thermostat.py
Original file line number Diff line number Diff line change
@@ -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())