class JSONThermostat

Public Class Methods

new(settings = '') click to toggle source
# File lib/json_thermostat.rb, line 6
def initialize(settings = '')
  range = JSON.parse(settings)['range']

  @converter = Converter.new
  converted_temperature = @converter.convert_temperature(
    value: JSON.parse(settings)['temperature'], json_to_parse: settings
  )

  @thermostat = Thermostat.new(
    current_temperature: converted_temperature,
    wanted_temperature: converted_temperature,
    range: @converter.convert_range(value: range, json_to_parse: settings)
  )
end

Public Instance Methods

generate_json(args) click to toggle source
# File lib/json_thermostat.rb, line 34
def generate_json(args)
  cooling = args.fetch(:cooling, false)
  heating = args.fetch(:heating, false)

  output = { cooling: cooling, heating: heating }

  JSON.generate(output)
end
update(update_json = '') click to toggle source
# File lib/json_thermostat.rb, line 21
def update(update_json = '')
  temperature = JSON.parse(update_json)['temperature']

  @thermostat.temp(@converter.convert_temperature(
                     value: temperature, json_to_parse: update_json
                   ))
  @thermostat.update

  generate_json(
    cooling: @thermostat.cooling, heating: @thermostat.heating
  )
end