Exemplo n.º 1
0
 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])
Exemplo n.º 2
0
 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])
Exemplo n.º 3
0
 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])
Exemplo n.º 4
0
 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])
Exemplo n.º 5
0
def decode(values):
    cur = None
    try:
        cur = HeatPump.decode(values)
    except:
        return
    # Send an update back to ourself
    req = urllib2.Request("http://localhost/api/update")
    req.add_header('Content-Type', 'application/json')
    try:
        response = urllib2.urlopen(req, json.dumps({'data': cur}))
        _ = json.load(response)
    except:
        pass
Exemplo n.º 6
0
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")