Class: Sensibo::Pod

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, id) ⇒ Pod

Returns a new instance of Pod.



32
33
34
35
36
37
38
39
40
# File 'lib/sensibo.rb', line 32

def initialize(key, id)
  @apiKey = key
  @id = id
  @urlBase = 'https://home.sensibo.com/api/v2/'
  @urlEnd = '?apiKey=' + @apiKey
  
  getState
  getMeasurements
end

Instance Attribute Details

#currentHumidityObject (readonly)

Returns the value of attribute currentHumidity.



29
30
31
# File 'lib/sensibo.rb', line 29

def currentHumidity
  @currentHumidity
end

#currentTempObject (readonly)

Returns the value of attribute currentTemp.



29
30
31
# File 'lib/sensibo.rb', line 29

def currentTemp
  @currentTemp
end

#fanObject

Returns the value of attribute fan.



30
31
32
# File 'lib/sensibo.rb', line 30

def fan
  @fan
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'lib/sensibo.rb', line 29

def id
  @id
end

#measurementAgeObject (readonly)

Returns the value of attribute measurementAge.



29
30
31
# File 'lib/sensibo.rb', line 29

def measurementAge
  @measurementAge
end

#measurementTimeObject (readonly)

Returns the value of attribute measurementTime.



29
30
31
# File 'lib/sensibo.rb', line 29

def measurementTime
  @measurementTime
end

#modeObject

Returns the value of attribute mode.



30
31
32
# File 'lib/sensibo.rb', line 30

def mode
  @mode
end

#onObject

Returns the value of attribute on.



30
31
32
# File 'lib/sensibo.rb', line 30

def on
  @on
end

#targetTempObject

Returns the value of attribute targetTemp.



30
31
32
# File 'lib/sensibo.rb', line 30

def targetTemp
  @targetTemp
end

Instance Method Details

#getMeasurementsObject



55
56
57
58
59
60
61
62
63
# File 'lib/sensibo.rb', line 55

def getMeasurements
  podDataURL = @urlBase + 'pods/' + @id + '/measurements' + @urlEnd
  podData = JSON.parse(open(podDataURL).string)['result'][0]
  
  @measurementAge = podData['time']['secondsAgo']
  @measurementTime = podData['time']['time']
  @currentTemp = podData['temperature']
  @currentHumidity = podData['humidity']    
end

#getStateObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sensibo.rb', line 42

def getState
  stateIDsURL = @urlBase + 'pods/' + @id + '/acStates' + @urlEnd
  stateID = JSON.parse(open(stateIDsURL).string)['result'][0]['id']

  stateURL = @urlBase + 'pods/' + @id + '/acStates/' + stateID + @urlEnd
  stateData = JSON.parse(open(stateURL).string)['result']['acState']
  
  @on = stateData['on']
  @mode = stateData['mode']
  @fan = stateData['fan']
  @targetTemp = stateData['targetTemperature']
end

#setStateObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sensibo.rb', line 72

def setState
  podUpdateURL = @urlBase + 'pods/' + @id + '/acStates' + @urlEnd

  response = HTTParty.post(
    podUpdateURL,
    { 
      :body => { 'acState' => {"on" => @on, "mode" => @mode, "fanLevel" => @fan, "targetTemperature" => @targetTemp } }.to_json,
      :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
    }
  )
end

#update(on: @on, mode: @mode, fan: @fan, targetTemp: @targetTemp) ⇒ Object



65
66
67
68
69
70
# File 'lib/sensibo.rb', line 65

def update (on: @on, mode: @mode, fan: @fan, targetTemp: @targetTemp)
  @on = on
  @mode = mode
  @fan = fan
  @targetTemp = targetTemp
end