Class: RubyMyq::Device::GarageDoor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_myq/device/garage_door.rb

Instance Method Summary collapse

Constructor Details

#initialize(device, headers) ⇒ GarageDoor

Returns a new instance of GarageDoor.



8
9
10
11
12
13
# 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

Instance Method Details

#change_door_state(command) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# 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

#closeObject



23
24
25
# File 'lib/ruby_myq/device/garage_door.rb', line 23

def close
  change_door_state('close')
end

#nameObject



15
16
17
# File 'lib/ruby_myq/device/garage_door.rb', line 15

def name
  @device['name']
end

#openObject



19
20
21
# File 'lib/ruby_myq/device/garage_door.rb', line 19

def open
  change_door_state('open')
end

#request_door_stateObject



37
38
39
40
41
42
43
44
45
# 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

#statusObject



27
28
29
30
# File 'lib/ruby_myq/device/garage_door.rb', line 27

def status
  state = request_door_state
  state['door_state']
end

#status_sinceObject



32
33
34
35
# File 'lib/ruby_myq/device/garage_door.rb', line 32

def status_since
  state = request_door_state
  state['last_update']
end