class Thermostat

Determines if the heating should be turned on @example

message = { wanted_value: 21.0, range: 1.0 }
thermo = Thermostat.new(message)
thermo.update_current(18)
thermo.update_thermo

Attributes

airco[RW]
current_value[RW]
heating[RW]
range[RW]
wanted_value[RW]

Public Class Methods

new(args) click to toggle source

Initializes the thermostat with wanted value, range and unit @param args [Hash] @option args [Numeric] :wanted_value the wanted value @option args [Numeric] :range the range that the value may defer @option args [String] :unit the unit of the value

# File lib/thermostat.rb, line 15
def initialize(args)
  @wanted_value = args[:wanted_value]
  @range = args[:range]
end

Public Instance Methods

return_airco() click to toggle source

@return [boolean] return if airco should be turned on

# File lib/thermostat.rb, line 46
def return_airco
  current_value > (wanted_value + range)
end
return_heating() click to toggle source

@return [boolean] return if heating should be turned on

# File lib/thermostat.rb, line 51
def return_heating
  current_value < (wanted_value - range)
end
update_current(current_value) click to toggle source

Update the current value with given value @param current_value [Numeric]

# File lib/thermostat.rb, line 33
def update_current(current_value)
  @current_value = current_value
end
update_range(range) click to toggle source

Update the range

# File lib/thermostat.rb, line 21
def update_range(range)
  @range = range
end
update_thermo() click to toggle source

Give return if the airco or heater should be turned on @return [String] return visually if airco or heating should be turned on

# File lib/thermostat.rb, line 39
def update_thermo
  airco = return_airco
  heating = return_heating
  "{\"cooling\":#{airco},\"heating\":#{heating}}"
end
update_wanted(wanted_value) click to toggle source

Update the wanted value with given value @param wanted_value [Numeric]

# File lib/thermostat.rb, line 27
def update_wanted(wanted_value)
  @wanted_value = wanted_value
end