Class: Artoo::Adaptors::Pebble
- Inherits:
-
Adaptor
- Object
- Adaptor
- Artoo::Adaptors::Pebble
- Defined in:
- lib/artoo/adaptors/pebble.rb
Overview
Connect to a pebble device
Constant Summary collapse
- RETRY_COUNT =
Number of retries when connecting
5
Instance Attribute Summary collapse
-
#pebble ⇒ Object
readonly
Returns the value of attribute pebble.
Instance Method Summary collapse
-
#connect ⇒ Boolean
Creates a connection with device.
-
#disconnect ⇒ Boolean
Closes connection with device.
-
#finalize ⇒ Boolean
Closes connection with device if connected.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Uses method missing to call device actions.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Uses method missing to call device actions
51 52 53 |
# File 'lib/artoo/adaptors/pebble.rb', line 51 def method_missing(method_name, *arguments, &block) pebble.send(method_name, *arguments, &block) end |
Instance Attribute Details
#pebble ⇒ Object (readonly)
Returns the value of attribute pebble.
9 10 11 |
# File 'lib/artoo/adaptors/pebble.rb', line 9 def pebble @pebble end |
Instance Method Details
#connect ⇒ Boolean
Creates a connection with device
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/artoo/adaptors/pebble.rb', line 22 def connect @retries_left = RETRY_COUNT require 'pebble' unless defined?(::Pebble) begin @pebble = ::Pebble::Watch.new(parent.connection_id, connect_to) @pebble.connect super return true rescue Errno::EBUSY, Errno::ECONNREFUSED => e @retries_left -= 1 if @retries_left > 0 retry else Logger.error e. Logger.error e.backtrace.inspect return false end end end |
#disconnect ⇒ Boolean
Closes connection with device
44 45 46 47 |
# File 'lib/artoo/adaptors/pebble.rb', line 44 def disconnect pebble.disconnect if connected? super end |
#finalize ⇒ Boolean
Closes connection with device if connected
16 17 18 |
# File 'lib/artoo/adaptors/pebble.rb', line 16 def finalize pebble.disconnect if connected? end |