Class: RubyMyq::Device::GarageDoor
- Inherits:
-
Object
- Object
- RubyMyq::Device::GarageDoor
- Defined in:
- lib/ruby_myq/device/garage_door.rb
Instance Method Summary collapse
- #change_door_state(command) ⇒ Object
- #close ⇒ Object
-
#initialize(device, headers) ⇒ GarageDoor
constructor
A new instance of GarageDoor.
- #name ⇒ Object
- #open ⇒ Object
- #request_door_state ⇒ Object
- #status ⇒ Object
- #status_since ⇒ Object
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' = { headers: @headers, body: { action_type: command }.to_json, format: :json # debug_output: STDOUT } HTTParty.put(action_uri, ) end |
#close ⇒ Object
23 24 25 |
# File 'lib/ruby_myq/device/garage_door.rb', line 23 def close change_door_state('close') end |
#name ⇒ Object
15 16 17 |
# File 'lib/ruby_myq/device/garage_door.rb', line 15 def name @device['name'] end |
#open ⇒ Object
19 20 21 |
# File 'lib/ruby_myq/device/garage_door.rb', line 19 def open change_door_state('open') end |
#request_door_state ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_myq/device/garage_door.rb', line 37 def request_door_state = { headers: @headers, format: :json # debug_output: STDOUT } response = HTTParty.get(@device_uri, ) response['state'] end |
#status ⇒ Object
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_since ⇒ Object
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 |