Exemple #1
0
 def __init__(self):
     super(ActionThread, self).__init__()
     self.alive = threading.Event()
     self.alive.set()
     self.queue = Queue.Queue()
     self.device = gatt.connect("20:C3:8F:F3:09:98")
     self.current_state = state.from_device(self.device)
Exemple #2
0
def get_state(address):
    if state_map.get(address) is None or state_map.get(address) is False:
        device = gatt.connect(address)
        state_map[address] = state.from_device(device)
        return state_map[address]
    else:
        return state_map[address]
Exemple #3
0
 def __init__(self):
     super(ActionThread, self).__init__()
     self.alive = threading.Event()
     self.alive.set()
     self.queue = Queue.Queue()
     self.device = gatt.connect("20:C3:8F:F3:09:98")
     self.current_state = state.from_device(self.device)
Exemple #4
0
def toggle(address):
    current_state = get_state(address)
    device = gatt.connect(address)
    new_state = state.from_device(device)

    if str(current_state.get_brightness()) != '0':
        if str(new_state.get_brightness()) == '0':
            new_state.set_brightness(current_state.get_brightness())
        else:
            new_state.set_brightness(0)
    else:
        state_map[address].set_brightness(100)
        new_state.set_brightness(100)

    new_state.write(device)

    device.disconnect()