class Sesame::Sesame

Public Class Methods

new(attrs = {}) click to toggle source
# File lib/sesame/sesame.rb, line 5
def initialize(attrs = {})
  @state = attrs
end

Public Instance Methods

battery() click to toggle source
# File lib/sesame/sesame.rb, line 22
def battery
  @state['battery'].to_i
end
device_id() click to toggle source
# File lib/sesame/sesame.rb, line 9
def device_id
  @state['device_id']
end
inspect() click to toggle source
# File lib/sesame/sesame.rb, line 34
def inspect
  %(#<#{self.class.name}:#{format('0x%<object_id>.14x', object_id: (object_id << 1))} device_id: #{device_id}>)
end
lock() click to toggle source
# File lib/sesame/sesame.rb, line 26
def lock
  control(command: 'lock')
end
locked()
Alias for: locked?
locked?() click to toggle source
# File lib/sesame/sesame.rb, line 13
def locked?
  truthy?(@state['locked'])
end
Also aliased as: locked
refresh!() click to toggle source
# File lib/sesame/sesame.rb, line 38
def refresh!
  @state.merge!(get_sesame(device_id: device_id))
  self
end
state() click to toggle source
# File lib/sesame/sesame.rb, line 18
def state
  locked? ? 'locked' : 'unlocked'
end
unlock() click to toggle source
# File lib/sesame/sesame.rb, line 30
def unlock
  control(command: 'unlock')
end

Private Instance Methods

control(command:) click to toggle source
# File lib/sesame/sesame.rb, line 49
def control(command:)
  control_sesame(device_id: device_id, command: command)
  refresh!
  true
end
truthy?(value) click to toggle source
# File lib/sesame/sesame.rb, line 45
def truthy?(value)
  (value == true) || (value == 'true')
end