class Cassia::ResponseHandlers::DiscoverCharOfService

Public Class Methods

new(access_controller, router: , device_mac: , service_uuid: ) click to toggle source
# File lib/cassia/response_handlers/discover_char_of_service.rb, line 4
def initialize(access_controller, router: , device_mac: , service_uuid: )
  @access_controller = access_controller
  @router = router
  @device_mac = device_mac
  @service_uuid = service_uuid
end

Public Instance Methods

handle(response) click to toggle source
# File lib/cassia/response_handlers/discover_char_of_service.rb, line 11
def handle(response)
  if response.success?
    handle_success(response)
  else
    handle_failure(response)
  end
  response.success?
end

Private Instance Methods

handle_failure(response) click to toggle source
# File lib/cassia/response_handlers/discover_char_of_service.rb, line 32
def handle_failure(response)
  @access_controller.error = response.body
end
handle_success(response) click to toggle source
# File lib/cassia/response_handlers/discover_char_of_service.rb, line 22
def handle_success(response)
  device = @router.connected_devices.detect {|device| device.mac == @device_mac}
  service = device.services.detect {|service| service.uuid == @service_uuid}
  response.body.each do |char|
    new_char = Characteristic.new(char)
    service.characteristics << new_char
    device.characteristics << new_char
  end
end