diff options
author | Loek Le Blansch <32883851+lonkaars@users.noreply.github.com> | 2021-08-13 14:03:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-13 14:03:33 +0200 |
commit | f1872e3b036e679d8e6b5f8e08c31da18caaa37a (patch) | |
tree | d5ff7c3656868780a4f29461eb3bbec535ec3cfa /main.py | |
parent | b8c9fc19e6e35679a1b9125396448987d7a6e8d0 (diff) | |
parent | 886630c94bd76b5bec9aa5b2eeb8a6da7d6a0cc2 (diff) |
Merge pull request #1 from lonkaars/homeassistant
homebridge to homeassistant
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/main.py b/main.py deleted file mode 100644 index d2debb7..0000000 --- a/main.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/python3 -from bluepy.btle import Peripheral, ADDR_TYPE_PUBLIC, BTLEDisconnectError -import threading -import time -import sys - -mac = sys.argv[1] -dev = None -messages = [] - -def verify_connection(): - global dev - while dev == None or dev.getState() == 'disc': - try: - dev = Peripheral(mac, ADDR_TYPE_PUBLIC) - except BTLEDisconnectError as e: - continue - -def makemsg(r, g, b, l=0): - return bytes([ - int(g > 0), g, - 0x00, 0x00, - int(b > 0), b, - int(r > 0), r, - int(l > 0), l, - ]) - -def keep_alive(): - while True: - global messages - messages.append((0x0001, bytes(10))) - time.sleep(10) - -def user_input(): - for line in sys.stdin: - r, g, b, l = [ int(x, 16) for x in [ line.strip()[i:i+2] for i in range(0, 8, 2) ] ] - messages.append((0x002a, makemsg(r, g, b, l))) - -threading.Thread(target=keep_alive).start() -threading.Thread(target=user_input).start() - -verify_connection() -while True: - if len(messages) < 1: continue - message = messages.pop(0) - verify_connection() - dev.writeCharacteristic(message[0], bytearray(message[1])) - |