class JSONThermostat
Attributes
thermostat[R]
@return returns the internal thermostat
Public Class Methods
new(settings = '')
click to toggle source
The [initialize] method creates a JSONThermostat
@param settings [String] a json object containing the following attributes
* temperature [Double] the wanted temperature * range [Double] the lower and upper margin around temperature * unit [String, nil] optionally an unit can be given, defaults to celcius
@example
JSONThermostat.new('{"temperature": 20.0, "range": 1.0, "unit": "celcius"}')
# File lib/json_thermostat.rb, line 16 def initialize(settings = '') json = JSON.parse(settings) temp, range = 0.0 if json.include? 'unit' temp = Convert.convert_absolute(input: json['temperature'], from_unit: json['unit'], to_unit: 'celsius') range = Convert.convert_relative(input: json['range'], from_unit: json['unit'], to_unit: 'celsius') else temp = json['temperature'] range = json['range'] end @thermostat = Thermostat.new(range: range, temp_wanted: temp, temp_curr: temp) end
Public Instance Methods
update(data = '')
click to toggle source
The [update] method updates the JSONThermostat
with a new temperature @param data [String] a json object containing the temperature input
* temperature [Double] the new current temperature * unit [String, nil] optionally an unit can be given, defaults to celcius
@return [String] a json object containing the temperature control status
* cooling [Bool] the status of the airo * heating [Bool] the status of the heater
@example
thermostat.update('{"temperature": 15}') #returns: '{"cooling": false, "heating": true}'
# File lib/json_thermostat.rb, line 39 def update(data = '') json = JSON.parse(data) temp = 0.0 temp = if json.include? 'unit' Convert.convert_absolute(input: json['temperature'], from_unit: json['unit'], to_unit: 'celsius') else json['temperature'] end @thermostat.temp_curr = temp @thermostat.check_temp JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heater) end