class SensiParty::Sensi
Constants
- SUCCESS_CODE
Public Class Methods
new()
click to toggle source
# File lib/sensi_party/sensi.rb, line 7 def initialize @username = '' @password = '' @baseUrl = 'https://bus-serv.sensicomfort.com' @defaultHeaders = { 'X-Requested-With' => 'XMLHttpRequest', 'Accept'=> 'application/json; version=1, */*; q=0.01' } @cookies = nil @connectionToken = nil @thermostats = nil end
Public Instance Methods
getThermostats()
click to toggle source
# File lib/sensi_party/sensi.rb, line 52 def getThermostats response = nil url = "#{@baseUrl}/api/thermostats" additionalOpts = { headers: @defaultHeaders.merge({'Accept-Encoding': 'gzip, deflate, sdch'}), cookies: @cookies } response = self.sendRequest(url, :get, additionalOpts) json = JSON.parse(response) @thermostats = json end
negotiate()
click to toggle source
# File lib/sensi_party/sensi.rb, line 43 def negotiate response = nil url = "#{@baseUrl}/realtime/negotiate" response = self.sendRequest(url, :get) json = JSON.parse(response) @connectionToken = json['ConnectionToken'] end
setHeat(temperature)
click to toggle source
# File lib/sensi_party/sensi.rb, line 66 def setHeat(temperature) response = nil url = "#{@baseUrl}/realtime/send" myThermostat = @thermostats.first additionalOpts = { headers: @defaultHeaders.merge({ 'Accept-Encoding': 'gzip, deflate', }), params: { transport: 'longPolling', connectionToken: self.getConnectionToken() }, cookies: @cookies, payload: URI.encode_www_form({ 'H': 'thermostat-v1', 'M': 'SetHeat', 'A': [myThermostat['ICD'], temperature, 'F'], 'I': 1 }), timeout: nil } response = self.sendRequest(url, :post, additionalOpts) end
start()
click to toggle source
# File lib/sensi_party/sensi.rb, line 20 def start self.authorize do self.negotiate end end
Protected Instance Methods
getConnectionToken()
click to toggle source
# File lib/sensi_party/sensi.rb, line 94 def getConnectionToken @connectionToken ||= self.negotiate() end
sendRequest(url, method, opts={})
click to toggle source
# File lib/sensi_party/sensi.rb, line 98 def sendRequest(url, method, opts={}) response = nil defaultArgs = { url: url, method: method } begin response = RestClient::Request.execute(defaultArgs.merge(opts)) rescue RestClient::ExceptionWithResponse => err puts "RestClient::ExceptionWtihResponse #{err}" rescue Exception => err puts err end return response end