def test_offset_decode(self): """ Cut off the start, check we can find it part way through """ as_ints = HeatPump.decode(self.timings[123:]) self.assertListEqual(as_ints, self.byte_codes) hp = HeatPump() hp.load_bytes(as_ints) state = hp.get_json_state() for key in self.decoded: self.assertEqual(self.decoded[key], state[key])
def test_half_decode(self): """ Load only the first message """ as_ints = HeatPump.decode(self.timings[0:291]) self.assertListEqual(as_ints, self.byte_codes) hp = HeatPump() hp.load_bytes(as_ints) state = hp.get_json_state() for key in self.decoded: self.assertEqual(self.decoded[key], state[key])
def test_simple_decode(self): """ Decode a simple successfully captured input """ as_ints = HeatPump.decode(self.timings) self.assertListEqual(as_ints, self.byte_codes) hp = HeatPump() hp.load_bytes(as_ints) state = hp.get_json_state() for key in self.decoded: self.assertEqual(self.decoded[key], state[key])
def test_half_working(self): """ Mess up the checksum in the second half, the should still load """ self.timings[-6] = 1300 as_ints = HeatPump.decode(self.timings) self.assertListEqual(as_ints, self.byte_codes) hp = HeatPump() hp.load_bytes(as_ints) state = hp.get_json_state() for key in self.decoded: self.assertEqual(self.decoded[key], state[key])
def decode(values): global cur global last hp = HeatPump() last = cur try: print(len(values)) cur = HeatPump.decode(values) except: return print("Done it!!!!!!!!!") print(cur) try: hp.load_bytes(cur) except Exception as e: print(e) print("Failed decode")