Class: Thermostat

Inherits:
Object
  • Object
show all
Defined in:
lib/thermostat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Thermostat

The [initialize] method creates a Thermostat

Parameters:

  • 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



19
20
21
22
23
24
25
# 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

Instance Attribute Details

#aircoObject (readonly)

Returns the status of the airco.

Returns:

  • the status of the airco



10
11
12
# File 'lib/thermostat.rb', line 10

def airco
  @airco
end

#heaterObject (readonly)

Returns the status of the heater.

Returns:

  • the status of the heater



12
13
14
# File 'lib/thermostat.rb', line 12

def heater
  @heater
end

#rangeDouble

Returns the lower and upper margin around the wanted temperature.

Returns:

  • (Double)

    the lower and upper margin around the wanted temperature



8
9
10
# File 'lib/thermostat.rb', line 8

def range
  @range
end

#temp_currDouble

Sets the current temperature

Returns:

  • (Double)

    the current temperature



4
5
6
# File 'lib/thermostat.rb', line 4

def temp_curr
  @temp_curr
end

#temp_wantedDouble

Returns the wanted temperature.

Returns:

  • (Double)

    the wanted temperature



6
7
8
# File 'lib/thermostat.rb', line 6

def temp_wanted
  @temp_wanted
end

Instance Method Details

#check_tempObject

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



28
29
30
31
32
33
34
35
36
37
38
39
# 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