コード例 #1
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")
コード例 #2
0
ファイル: server.py プロジェクト: rsanger/heatpump-controller
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
コード例 #3
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])
コード例 #4
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])
コード例 #5
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])
コード例 #6
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])
コード例 #7
0
ファイル: server.py プロジェクト: rsanger/heatpump-controller
                grabbed = []
        else:  # timeout
            if len(grabbed) >= 291:
                decode(grabbed)
            grabbed = []


t = threading.Thread(target=receiver)
t.daemon = True
t.start()

try:
    with open(app.config['SAVE_STATE_PATH'], 'rb') as fstate:
        pump = pickle.load(fstate)
except:
    pump = HeatPump()


def save_state():
    if app.config['SAVE_STATE_PATH']:
        try:
            with open(app.config['SAVE_STATE_PATH'], 'wb') as fstate:
                pickle.dump(pump, fstate)
        except:
            pass


def program_heatpump():
    """ Send current state as IR message """
    global f
    global pump