def _parse_week_program(self, buffer): program = [] for day in range(0, 7): day_schedules = [] offset = day * 26 day_config = buffer[offset:offset + 26] start = datetime.time() for schedule_offset in range(0, 26, 2): schedule_bytes = day_config[schedule_offset:schedule_offset + 2] temp, time = unpack_temp_and_time(schedule_bytes) schedule = ProgramSchedule(temp, start, time) day_schedules.append(schedule) start = schedule.end_minutes if time >= 1440: break program.append(day_schedules) return program
def test_stupid_payload(self): expected = bytearray([ int(x, 16) for x in "00 04 10 00 00 00 12 2b 65 01 02 40 49 4c 6e 40 cb 4d 20".split() ]) # base string | rf addr |r| d |s1 |s2 |s3 |s4 msg = SetProgramMessage('122b65', 1, 0, [ ProgramSchedule(16, datetime.time(), datetime.time(6, 5)), ProgramSchedule(19, datetime.time(6, 5), datetime.time(9, 10)), ProgramSchedule(16, datetime.time(9, 10), datetime.time(16, 55)), ProgramSchedule(19, datetime.time(16, 55), 1440), ]) data = msg.get_payload() # print("") # print(" ".join(["{0}".format(str(i).rjust(2, ' ')) for i in range(0, max(len(data), len(expected)))])) # print(" ".join(["{0:2X}".format(i) for i in bytearray(data)])) # print(" ".join(["{0:2X}".format(i) for i in expected])) # print("") self.assertEqual(data, expected)
def test_get_payload_one(self): msg = SetProgramMessage('122b65', 1, 6, [ProgramSchedule(16, 0, datetime.time(6, 5))]) b64payload = msg.to_bytes()[2:] data = base64.b64decode(b64payload) expected = bytearray([ 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, # base string 0x12, 0x2b, 0x65, # rf addr 0x01, # room 0x01, # weekday (*cube* weekday) 0x40, 0x49, ]) self.assertEqual(data, expected)
def test_thermostat_config(self): response = ConfigurationResponse(ThermostatConfigurationBytes) self.assertEqual(response.device_type, DeviceRadiatorThermostatPlus) self.assertEqual(response.device_addr, '122B65') self.assertEqual(response.serial_number, 'MEQ147299') self.assertEqual(response.comfort_temperature, 29.5) self.assertEqual(response.eco_temperature, 19.5) self.assertEqual(response.max_set_point_temperature, 30.5) self.assertEqual(response.min_set_point_temperature, 4.5) self.assertEqual(response.temperature_offset, 0.0) self.assertEqual(response.window_open_temperature, 12.0) self.assertEqual(response.window_open_duration, 15.0) self.assertEqual(response.boost_duration, 20.0) self.assertEqual(response.boost_valve_setting, 90.0) self.assertEqual(response.decalcification_day, 0) self.assertEqual(response.decalcification_hour, 12) self.assertEqual(response.max_valve_setting, 100) self.assertTrue(len(response.week_program) > 0) self.assertEqual(response.week_program, [ [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time(6, 0)), ProgramSchedule(30.0, datetime.time(6, 0), datetime.time( 22, 35)), ProgramSchedule(17.0, datetime.time(22, 35), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time(6, 0)), ProgramSchedule(30.0, datetime.time(6, 0), datetime.time( 22, 5)), ProgramSchedule(17.0, datetime.time(22, 5), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time( 5, 30)), ProgramSchedule(30.0, datetime.time(5, 30), datetime.time( 7, 50)), ProgramSchedule(17.0, datetime.time(7, 50), datetime.time(16, 45)), ProgramSchedule(30.0, datetime.time(16, 45), datetime.time(22, 50)), ProgramSchedule(17.0, datetime.time(22, 50), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time( 5, 30)), ProgramSchedule(30.0, datetime.time(5, 30), datetime.time( 7, 50)), ProgramSchedule(17.0, datetime.time(7, 50), datetime.time(16, 45)), ProgramSchedule(30.0, datetime.time(16, 45), datetime.time(22, 50)), ProgramSchedule(17.0, datetime.time(22, 50), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time( 5, 30)), ProgramSchedule(30.0, datetime.time(5, 30), datetime.time( 7, 50)), ProgramSchedule(17.0, datetime.time(7, 50), datetime.time(16, 45)), ProgramSchedule(30.0, datetime.time(16, 45), datetime.time(22, 50)), ProgramSchedule(17.0, datetime.time(22, 50), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time( 5, 30)), ProgramSchedule(30.0, datetime.time(5, 30), datetime.time( 7, 50)), ProgramSchedule(17.0, datetime.time(7, 50), datetime.time(16, 45)), ProgramSchedule(30.0, datetime.time(16, 45), datetime.time(22, 50)), ProgramSchedule(17.0, datetime.time(22, 50), 1440), ], [ ProgramSchedule(17.0, datetime.time(0, 0), datetime.time( 5, 30)), ProgramSchedule(30.0, datetime.time(5, 30), datetime.time( 7, 50)), ProgramSchedule(17.0, datetime.time(7, 50), datetime.time(16, 45)), ProgramSchedule(30.0, datetime.time(16, 45), datetime.time(22, 50)), ProgramSchedule(17.0, datetime.time(22, 50), 1440), ], ])
def test_constructor1(self): ps = ProgramSchedule(10, 60, 60) self.assertEqual(ps.temperature, 10) self.assertEqual(ps.begin_minutes, 60) self.assertEqual(ps.end_minutes, 60)
def test_constructor4(self): ps = ProgramSchedule(10, datetime.time(1), datetime.time(1)) self.assertEqual(ps.temperature, 10) self.assertEqual(ps.begin_minutes, 60) self.assertEqual(ps.end_minutes, 60)