Example #1
0
def got_button(bd_addr):
    cc = fliclib.ButtonConnectionChannel(bd_addr)
    cc.on_button_click_or_hold = lambda channel, click_type, was_queued, time_diff: \
     requests.get('http://10.0.1.31/command.htm?key=ENTER') if str(click_type) == 'ClickType.ButtonClick'  else requests.get('http://10.0.1.31/command.htm?key=CANCEL')

    cc.on_connection_status_changed = lambda channel, connection_status, disconnect_reason: \
     print(channel.bd_addr + " " + str(connection_status) + (" " + str(disconnect_reason) if connection_status == fliclib.ConnectionStatus.Disconnected else ""))
    client.add_connection_channel(cc)
Example #2
0
def got_button(bd_addr):
    cc = fliclib.ButtonConnectionChannel(bd_addr)
    cc.on_button_up_or_down = \
     lambda channel, click_type, was_queued, time_diff: \
      print(channel.bd_addr + " " + str(click_type))
    cc.on_connection_status_changed = \
     lambda channel, connection_status, disconnect_reason: \
      print(channel.bd_addr + " " + str(connection_status) + (" " + str(disconnect_reason) if connection_status == fliclib.ConnectionStatus.Disconnected else ""))
    client.add_connection_channel(cc)
Example #3
0
def got_button(bd_addr):
    cc = fliclib.ButtonConnectionChannel(bd_addr)
    cc.on_button_up_or_down = \
        lambda channel, click_type, was_queued, time_diff: \
            my_publish(start_topic+channel.bd_addr.replace(":",""),str(click_type).replace("ClickType.",""))
    cc.on_connection_status_changed = \
        lambda channel, connection_status, disconnect_reason: \
            print(channel.bd_addr + " " + str(connection_status) + (" " + str(disconnect_reason) if connection_status == fliclib.ConnectionStatus.Disconnected else ""))
    client.add_connection_channel(cc)
Example #4
0
 def _got_button(self, bd_addr):
     """Creates a button connection channel and assigns the handler function for button presses for a particular button.
 
     Args:
         bd_addr: button address.
     """
     cc = fliclib.ButtonConnectionChannel(bd_addr)
     cc.on_button_single_or_double_click_or_hold = self._on_button_single_or_double_click_or_hold
     self.client.add_connection_channel(cc)
def onFlicNewVerifiedButton(bdAddr):
    cc = fliclib.ButtonConnectionChannel(bdAddr)

    cc.on_button_click_or_hold = onFlicButtonClickOrHold
    cc.on_connection_status_changed = onFlicButtonConnectionStatusChanged
    cc.on_create_connection_channel_response = \
        onFlicButtonCreateConnectionChannelResponse
    cc.on_removed = onFlicButtonConnectionChannelRemoved

    flicClient.add_connection_channel(cc)
Example #6
0
 def got_button(bd_addr):
     cc = fliclib.ButtonConnectionChannel(bd_addr)
     # Assign function to call when a button is clicked
     cc.on_button_single_or_double_click_or_hold = click_handler
     cc.on_connection_status_changed = \
      lambda channel, connection_status, disconnect_reason: \
       logger.info(channel.bd_addr + " " + str(connection_status) + (" " + str(disconnect_reason) if connection_status == fliclib.ConnectionStatus.Disconnected else ""))
     flic_client.add_connection_channel(cc)
     print(' OK')
     logger.info(bd_addr + ' OK')
Example #7
0
def on_adv_packet(scanner, bd_addr, name, rssi, is_private, already_verified):
    if already_verified:
        return

    if is_private:
        print(
            "Button " + bd_addr +
            " is currently private. Hold it down for 7 seconds to make it public."
        )
        return

    print("Found public button " + bd_addr + ", now connecting...")
    client.remove_scanner(scanner)

    def restart_scan():
        print("Restarting scan")
        client.add_scanner(scanner)

    def on_create(channel, error, connection_status):
        if connection_status == fliclib.ConnectionStatus.Ready:
            done(bd_addr)
        elif error != fliclib.CreateConnectionChannelError.NoError:
            print("Failed: " + str(error))
            restart_scan()
        else:
            client.set_timer(30 * 1000,
                             lambda: client.remove_connection_channel(channel))

    def on_removed(channel, removed_reason):
        print("Failed: " + str(removed_reason))
        restart_scan()

    def on_connection_status_changed(channel, connection_status,
                                     disconnect_reason):
        if connection_status == fliclib.ConnectionStatus.Ready:
            done(bd_addr)

    channel = fliclib.ButtonConnectionChannel(bd_addr)
    channel.on_create_connection_channel_response = on_create
    channel.on_removed = on_removed
    channel.on_connection_status_changed = on_connection_status_changed
    client.add_connection_channel(channel)
def got_button(bd_addr):
    cc = fliclib.ButtonConnectionChannel(bd_addr)
    cc.on_button_up_or_down = button_up_or_down
    cc.on_connection_status_changed = status_changed
    client.add_connection_channel(cc)
def got_info(items):
    print(items)
    for bd_addr in items["bd_addr_of_verified_buttons"]:
        cc = fliclib.ButtonConnectionChannel(bd_addr)
        cc.on_button_up_or_down = got_button
        client.add_connection_channel(cc)
Example #10
0
def got_button(bd_addr):
    cc = fliclib.ButtonConnectionChannel(bd_addr)
    cc.on_button_single_or_double_click_or_hold = button_cb
    cc.on_connection_status_changed = on_connection_status_changed_cb
    client.add_connection_channel(cc)
def got_button(bd_addr):
    channel = fliclib.ButtonConnectionChannel(bd_addr)
    channel.on_button_single_or_double_click_or_hold = handleButton
    flicClient.add_connection_channel(channel)