Class: NestApi::Thermostat

Inherits:
Object
  • Object
show all
Defined in:
lib/nest_api/thermostat.rb

Instance Method Summary collapse

Constructor Details

#initialize(device_id, token) ⇒ Thermostat



3
4
5
6
# File 'lib/nest_api/thermostat.rb', line 3

def initialize(device_id, token)
  @id = device_id
  @token = token
end

Instance Method Details

#get(property_id = '') ⇒ Object

Retrieve a property of a thermostat If no property_id is supplied, all properties of the thermostat will be returned



10
11
12
# File 'lib/nest_api/thermostat.rb', line 10

def get(property_id = '')
  HTTParty.get("#{NestApi::API_URL}/devices/thermostats/#{@id}/#{property_id}",  query: { auth: @token.access_token })
end

#update!(property_id:, value:) ⇒ Object

Set a thermostat property to a new value



15
16
17
18
19
20
21
# File 'lib/nest_api/thermostat.rb', line 15

def update!(property_id:, value:)
  HTTParty.put("#{NestApi::API_URL}/devices/thermostats/#{@id}",
    query: { auth: @token.access_token },
    body: { "#{property_id}" => value }.to_json,
    headers: { 'Content-Type' => 'application/json'
  })
end