class Thermostat
Attributes
current_temp[RW]
range[RW]
unit[RW]
wanted_temp[RW]
Public Instance Methods
output()
click to toggle source
@return [JSON] returns the JSON-output
# File lib/thermostat.rb, line 41 def output if (@wanted_temp + @range) < @current_temp JSON.generate(cooling: true, heating: false) elsif (@wanted_temp - @range) > @current_temp JSON.generate(cooling: false, heating: true) elsif ((@wanted_temp - @range) <= @current_temp) && ((@wanted_temp + @range) >= @current_temp) JSON.generate(cooling: false, heating: false) end end
range_set(range)
click to toggle source
@return [Integer] returns the range (converted to fahrenheit if necessary)
# File lib/thermostat.rb, line 10 def range_set(range) @range = if @unit == 'fahrenheit' (range * 0.5555555) / 2 # 5/9 won't work so I take 0.5555555 else range / 2 end end
unit_set(unit)
click to toggle source
Sets the unit value
# File lib/thermostat.rb, line 5 def unit_set(unit) @unit = unit end
update_temp(current_temp)
click to toggle source
@return [Integer] returns the current temperature (converted to fahrenheit or kelvin if necessary)
# File lib/thermostat.rb, line 30 def update_temp(current_temp) @current_temp = if @unit == 'fahrenheit' (current_temp - 32) / 1.8 # 9/5 won't work so I take 1.8 elsif @unit == 'kelvin' (current_temp - 273.15) else current_temp end end
wanted_temp_set(wanted_temp)
click to toggle source
@return [Integer] returns the wanted temperature (converted to fahrenheit or kelvin if necessary)
# File lib/thermostat.rb, line 19 def wanted_temp_set(wanted_temp) @wanted_temp = if @unit == 'fahrenheit' (wanted_temp - 32) / 1.8 # 9/5 won't work so I take 1.8 elsif @unit == 'kelvin' (wanted_temp - 273.15) else wanted_temp end end