class Thermostat

Attributes

airco[R]

@return the status of the airco

heater[R]

@return the status of the heater

range[RW]

@return [Double] the lower and upper margin around the wanted temperature

temp_curr[RW]

Sets the current temperature @return [Double] the current temperature

temp_wanted[RW]

@return [Double] the wanted temperature

Public Class Methods

new(args) click to toggle source

The [initialize] method creates a Thermostat @param settings [String] a json object containing the following attributes

* range [Double] the lower and upper margin around the wanted temperature
* temp_wanted [Double] the wanted temperature
* temp_curr [Double] the current temperature
# File lib/thermostat.rb, line 19
def initialize(args)
  @range = args.fetch(:range, 1.0)
  @temp_wanted = args.fetch(:temp_wanted, 20.0)
  @temp_curr = args.fetch(:temp_curr, 20.0)
  @airco = false
  @heater = false
end

Public Instance Methods

check_temp() click to toggle source

The [check_temp] method updates the airco and heater based on temp_curr

# File lib/thermostat.rb, line 28
def check_temp
  if @temp_curr > (@temp_wanted + @range / 2)
    @airco = true
    @heater = false
  elsif @temp_curr < (@temp_wanted - @range / 2)
    @airco = false
    @heater = true
  else
    @airco = false
    @heater = false
  end
end