Class: Sensibo::Pod
- Inherits:
-
Object
- Object
- Sensibo::Pod
- Defined in:
- lib/sensibo.rb
Instance Attribute Summary collapse
-
#batteryVoltage ⇒ Object
readonly
Returns the value of attribute batteryVoltage.
-
#currentHumidity ⇒ Object
readonly
Returns the value of attribute currentHumidity.
-
#currentTemp ⇒ Object
readonly
Returns the value of attribute currentTemp.
-
#fan ⇒ Object
Returns the value of attribute fan.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#measurementAge ⇒ Object
readonly
Returns the value of attribute measurementAge.
-
#measurementTime ⇒ Object
readonly
Returns the value of attribute measurementTime.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#on ⇒ Object
Returns the value of attribute on.
-
#swing ⇒ Object
Returns the value of attribute swing.
-
#targetTemp ⇒ Object
Returns the value of attribute targetTemp.
Instance Method Summary collapse
- #getBattery ⇒ Object
- #getMeasurements ⇒ Object
- #getState ⇒ Object
-
#initialize(key, id) ⇒ Pod
constructor
A new instance of Pod.
- #setState ⇒ Object
- #update(on: @on, mode: @mode, fan: @fan, targetTemp: @targetTemp, swing: @swing) ⇒ Object
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
#batteryVoltage ⇒ Object (readonly)
Returns the value of attribute batteryVoltage.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def batteryVoltage @batteryVoltage end |
#currentHumidity ⇒ Object (readonly)
Returns the value of attribute currentHumidity.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def currentHumidity @currentHumidity end |
#currentTemp ⇒ Object (readonly)
Returns the value of attribute currentTemp.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def currentTemp @currentTemp end |
#fan ⇒ Object
Returns the value of attribute fan.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def fan @fan end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def id @id end |
#measurementAge ⇒ Object (readonly)
Returns the value of attribute measurementAge.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def measurementAge @measurementAge end |
#measurementTime ⇒ Object (readonly)
Returns the value of attribute measurementTime.
29 30 31 |
# File 'lib/sensibo.rb', line 29 def measurementTime @measurementTime end |
#mode ⇒ Object
Returns the value of attribute mode.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def mode @mode end |
#on ⇒ Object
Returns the value of attribute on.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def on @on end |
#swing ⇒ Object
Returns the value of attribute swing.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def swing @swing end |
#targetTemp ⇒ Object
Returns the value of attribute targetTemp.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def targetTemp @targetTemp end |
Instance Method Details
#getBattery ⇒ Object
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 |
#getMeasurements ⇒ Object
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 |
#getState ⇒ Object
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 |
#setState ⇒ Object
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 |