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
41
# 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
  getBattery
end

Instance Attribute Details

#batteryVoltageObject (readonly)

Returns the value of attribute batteryVoltage.



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

def batteryVoltage
  @batteryVoltage
end

#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

#swingObject

Returns the value of attribute swing.



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

def swing
  @swing
end

#targetTempObject

Returns the value of attribute targetTemp.



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

def targetTemp
  @targetTemp
end

Instance Method Details

#getBatteryObject



67
68
69
70
71
72
# File 'lib/sensibo.rb', line 67

def getBattery
  podDataURL = @urlBase + 'pods/' + @id + '/measurements' + @urlEnd + '&fields=batteryVoltage'
  podData = JSON.parse(open(podDataURL).string)['result'][0]
  
  @batteryVoltage = podData['batteryVoltage']
end

#getMeasurementsObject



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

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



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

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']
  @swing = stateData['swing']
end

#setStateObject



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sensibo.rb', line 82

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

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

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



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

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