Class: JSONThermostat
- Inherits:
-
Object
- Object
- JSONThermostat
- Defined in:
- lib/json_thermostat.rb
Instance Attribute Summary collapse
-
#thermostat ⇒ Object
readonly
Returns the internal thermostat.
Instance Method Summary collapse
-
#initialize(settings = '') ⇒ JSONThermostat
constructor
The [initialize] method creates a JSONThermostat.
-
#update(data = '') ⇒ String
The [update] method updates the JSONThermostat with a new temperature.
Constructor Details
#initialize(settings = '') ⇒ JSONThermostat
The [initialize] method creates a JSONThermostat
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/json_thermostat.rb', line 16 def initialize(settings = '') json = JSON.parse(settings) temp, range = 0.0 if json.include? 'unit' temp = Convert.convert_absolute(input: json['temperature'], from_unit: json['unit'], to_unit: 'celsius') range = Convert.convert_relative(input: json['range'], from_unit: json['unit'], to_unit: 'celsius') else temp = json['temperature'] range = json['range'] end @thermostat = Thermostat.new(range: range, temp_wanted: temp, temp_curr: temp) end |
Instance Attribute Details
#thermostat ⇒ Object (readonly)
Returns the internal thermostat
7 8 9 |
# File 'lib/json_thermostat.rb', line 7 def thermostat @thermostat end |
Instance Method Details
#update(data = '') ⇒ String
The [update] method updates the JSONThermostat with a new temperature
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/json_thermostat.rb', line 39 def update(data = '') json = JSON.parse(data) temp = 0.0 temp = if json.include? 'unit' Convert.convert_absolute(input: json['temperature'], from_unit: json['unit'], to_unit: 'celsius') else json['temperature'] end @thermostat.temp_curr = temp @thermostat.check_temp JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heater) end |