class Cassia::ResponseHandlers::WriteCharByHandle
Public Class Methods
new(access_controller, router: , device_mac: , handle: , value: )
click to toggle source
# File lib/cassia/response_handlers/write_char_by_handle.rb, line 4 def initialize(access_controller, router: , device_mac: , handle: , value: ) @access_controller = access_controller @router = router @device_mac = device_mac @handle = handle @value = value end
Public Instance Methods
handle(response)
click to toggle source
# File lib/cassia/response_handlers/write_char_by_handle.rb, line 12 def handle(response) if response.success? return handle_success else handle_failure(response) end response.success? end
handle_failure(response)
click to toggle source
# File lib/cassia/response_handlers/write_char_by_handle.rb, line 36 def handle_failure(response) @access_controller.error = response.body end
handle_success()
click to toggle source
# File lib/cassia/response_handlers/write_char_by_handle.rb, line 21 def handle_success device = @router.connected_devices.detect {|device| device.mac == @device_mac} char = device.characteristics.detect {|char| char.handle == @handle || !char.descriptors.detect {|d| d.handle == @handle }.nil? } if char if @value == "0100" char.notification_on = true elsif @value == "0000" char.notification_on = false end else @access_controller.error = "Characteristic With Given Handle Not Found" end !(char.nil?) end