module Flic::Client::Features::GetButtonUuid

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/flic/client/features/get_button_uuid.rb, line 9
def initialize(*)
  @button_bluetooth_address_callbacks_semaphore = Mutex.new
  @button_bluetooth_address_callbacks = Hash.new { [] }

  super
end

Public Instance Methods

get_button_uuid(button_bluetooth_address, callback = Proc.new) click to toggle source
# File lib/flic/client/features/get_button_uuid.rb, line 16
def get_button_uuid(button_bluetooth_address, callback = Proc.new)
  command = Protocol::Commands::GetButtonUuid.new(bluetooth_address: button_bluetooth_address)

  @button_bluetooth_address_callbacks_semaphore.synchronize do
    @button_bluetooth_address_callbacks[command.bluetooth_address] << callback
  end

  send_command command
end

Private Instance Methods

handle_event(event) click to toggle source
Calls superclass method
# File lib/flic/client/features/get_button_uuid.rb, line 28
def handle_event(event)
  case event
    when Protocol::Events::GetButtonUuidResponse
      callback = @button_bluetooth_address_callbacks_semaphore.synchronize do
        @button_bluetooth_address_callbacks[event.bluetooth_address].shift
      end

      callback.call event.uuid if callback
    else
      super
  end
end