class RubyMyq::Device::GarageDoor

Public Class Methods

new(device, headers) click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 8
def initialize(device, headers)
  @device = device
  @headers = headers
  # API response includes incorrect verion number and http rather than https
  @device_uri = @device['href'].gsub(/v5/, 'v5.1').gsub(/http/, 'https')
end

Public Instance Methods

change_door_state(command) click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 47
def change_door_state(command)
  action_uri = @device_uri + '/Actions'

  options = {
    headers: @headers,
    body: { action_type: command }.to_json,
    format: :json
    # debug_output: STDOUT
  }
  HTTParty.put(action_uri, options)
end
close() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 23
def close
  change_door_state('close')
end
name() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 15
def name
  @device['name']
end
open() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 19
def open
  change_door_state('open')
end
request_door_state() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 37
def request_door_state
  options = {
    headers: @headers,
    format: :json
    # debug_output: STDOUT
  }
  response = HTTParty.get(@device_uri, options)
  response['state']
end
status() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 27
def status
  state = request_door_state
  state['door_state']
end
status_since() click to toggle source
# File lib/ruby_myq/device/garage_door.rb, line 32
def status_since
  state = request_door_state
  state['last_update']
end