class JSONThermostat
Attributes
current_value[RW]
measurment_unit[RW]
range[RW]
setting_unit[RW]
wanted_value[RW]
Public Class Methods
new(setjson)
click to toggle source
Initialize the thermostats wanted value, range and unit. @param [JSON] takes wanted value, range and unit from JSON input.
# File lib/json_thermostat.rb, line 10 def initialize(setjson) to_parse = JSON.parse(setjson) @wanted_value = to_parse['temperature'] @range = to_parse['range'] / 2.0 @setting_unit = to_parse['unit'] end
Public Instance Methods
calculator()
click to toggle source
# File lib/json_thermostat.rb, line 42 def calculator @calculator ||= Calculator.new end
check()
click to toggle source
Checks the current value by the wanted value and set on the heating or airco
# File lib/json_thermostat.rb, line 32 def check if @current_value > (wanted_value + range) set_airco elsif @current_value < (wanted_value - range) set_heating else everything_off end end
everything_off()
click to toggle source
# File lib/json_thermostat.rb, line 54 def everything_off '{\'cooling\':false,\'heating\':false}' end
set_airco()
click to toggle source
# File lib/json_thermostat.rb, line 46 def set_airco '{\'cooling\':true,\'heating\':false}' end
set_heating()
click to toggle source
# File lib/json_thermostat.rb, line 50 def set_heating '{\'cooling\':false,\'heating\':true}' end
update(setjson)
click to toggle source
Update the current value and his unit. @param [JSON] takes current value an unit from JSON input.
# File lib/json_thermostat.rb, line 19 def update(setjson) to_parse = JSON.parse(setjson) @current_value = to_parse['temperature'] @measurment_unit = to_parse['unit'] args = { unit: setting_unit, value: wanted_value } @wanted_value = calculator.calc_setting(args) args = { unit: measurment_unit, value: current_value } @current_value = calculator.calc_setting(args) check end