Class: Sensibo::Pod
- Inherits:
-
Object
- Object
- Sensibo::Pod
- Defined in:
- lib/sensibo.rb
Instance Attribute Summary collapse
-
#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.
-
#targetTemp ⇒ Object
Returns the value of attribute targetTemp.
Instance Method Summary collapse
- #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) ⇒ Object
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
#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 |
#targetTemp ⇒ Object
Returns the value of attribute targetTemp.
30 31 32 |
# File 'lib/sensibo.rb', line 30 def targetTemp @targetTemp end |
Instance Method Details
#getMeasurements ⇒ Object
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 |
#getState ⇒ Object
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 |
#setState ⇒ Object
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 |