From e0b2093a885080e65a5146427c5198ed506994a2 Mon Sep 17 00:00:00 2001 From: Dean Brundage Date: Sun, 4 Dec 2016 17:46:11 -0600 Subject: [PATCH] cleaning up logging --- Gemfile.lock | 2 - bin/thermostat | 41 +++-- lib/thermostat.rb | 6 +- .../hardware_controller/raspberry_pi.rb | 4 +- .../raspberry_pi/pin_cleaner.rb | 2 +- .../hardware_controller/raspberry_pi/relay.rb | 4 +- lib/thermostat/logger.rb | 162 ++++++++++++++++-- lib/thermostat/logger/formatter.rb | 20 +++ lib/thermostat/logging.rb | 23 +++ lib/thermostat/logging_adapter.rb | 6 +- lib/thermostat/sensor/temperature.rb | 2 +- lib/thermostat/simple.rb | 53 ++---- lib/thermostat/simple/controller.rb | 67 ++++++++ lib/thermostat/simple/state_machine.rb | 5 +- lib/thermostat/zone.rb | 4 +- .../cases/thermostat/logger/formatter_spec.rb | 3 + spec/cases/thermostat/logger_spec.rb | 46 +++-- spec/cases/thermostat/logging_spec.rb | 30 ++++ .../thermostat/simple/controller_spec.rb | 8 + spec/cases/thermostat_spec.rb | 8 +- thermostat.gemspec | 31 ++-- 21 files changed, 403 insertions(+), 124 deletions(-) create mode 100644 lib/thermostat/logger/formatter.rb create mode 100644 lib/thermostat/logging.rb create mode 100644 lib/thermostat/simple/controller.rb create mode 100644 spec/cases/thermostat/logger/formatter_spec.rb create mode 100644 spec/cases/thermostat/logging_spec.rb create mode 100644 spec/cases/thermostat/simple/controller_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 5132200..65966d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,6 @@ PATH remote: . specs: thermostat (0.1.0) - brogger rpi_gpio ruby-units ruby_i2c @@ -11,7 +10,6 @@ PATH GEM remote: https://rubygems.org/ specs: - brogger (0.1.0) coderay (1.1.1) coveralls (0.8.15) json (>= 1.8, < 3) diff --git a/bin/thermostat b/bin/thermostat index ebc4437..9a5764b 100755 --- a/bin/thermostat +++ b/bin/thermostat @@ -9,28 +9,31 @@ include Thermostat::HeatIndexCalculator def temperature; Unit.new(@sensor.temp, :tempC); end def relative_humidity_percent; @sensor.rh; end -Thermostat.logger.level = :debug +Thermostat.logger.level = :debug +Thermostat.logger.subsystem = :hardware @sensor = RubyI2C::Device::SI70XX.new puts "It is #{temperature >> "tempF"} with #{relative_humidity_percent.to_f}% relative humidity making the heat index #{heat_index >> "tempF"}" -cool_controller = Thermostat::HardwareController::RaspberryPi::Relay.new(17) -heat_controller = Thermostat::HardwareController::RaspberryPi::Relay.new(27) -fan_controller = Thermostat::HardwareController::RaspberryPi::Relay.new(22) +controller = Thermostat::Simple::Controller.new cool_relay: Thermostat::HardwareController::RaspberryPi::Relay.new(17), + fan_relay: Thermostat::HardwareController::RaspberryPi::Relay.new(22), + heat_relay: Thermostat::HardwareController::RaspberryPi::Relay.new(27), + cooldown_seconds: 0.25 -thermostat = Thermostat::Simple.new cooling_controller: cool_controller, - fanning_controller: fan_controller, - heating_controller: heat_controller, - name: :awesome +thermostat = Thermostat::Simple.new controller: controller, name: :awesome -thermostat.heat -sleep 0.75 -thermostat.cooldown -sleep 0.5 -thermostat.off -sleep 0.75 -thermostat.cool -sleep 0.75 -thermostat.cooldown -sleep 0.5 -thermostat.off +begin + thermostat.heat + sleep 0.75 + thermostat.cooldown + sleep 0.5 + thermostat.off + sleep 0.75 + thermostat.cool + sleep 0.75 + thermostat.cooldown + sleep 0.5 + thermostat.off +ensure + [ 17, 22, 27 ].each { |p| Thermostat::HardwareController::RaspberryPi::Relay.new(p).open } +end diff --git a/lib/thermostat.rb b/lib/thermostat.rb index dc983d2..53d2daf 100644 --- a/lib/thermostat.rb +++ b/lib/thermostat.rb @@ -1,16 +1,14 @@ -require 'brogger' require "thermostat/version" class Thermostat autoload :Config, File.join('thermostat', 'config') autoload :ConfigLoader, File.join('thermostat', 'config_loader') - autoload :Controller, File.join('thermostat', 'controller') - autoload :Fan, File.join('thermostat', 'fan') autoload :HardwareController, File.join('thermostat', 'hardware_controller') autoload :HeatIndexCalculator, File.join('thermostat', 'heat_index_calculator') autoload :InvalidSetpoint, File.join('thermostat', 'invalid_setpoint') autoload :Logger, File.join('thermostat', 'logger') + autoload :Logging, File.join('thermostat', 'logging') autoload :LoggingAdapter, File.join('thermostat', 'logging_adapter') autoload :Sensor, File.join('thermostat', 'sensor') autoload :Simple, File.join('thermostat', 'simple') @@ -18,7 +16,7 @@ class Thermostat autoload :StructInitializer, File.join('thermostat', 'struct_initializer') autoload :Zone, File.join('thermostat', 'zone') - extend Logger + extend Logging attr_reader :default_config diff --git a/lib/thermostat/hardware_controller/raspberry_pi.rb b/lib/thermostat/hardware_controller/raspberry_pi.rb index 30706f4..ffd41f7 100644 --- a/lib/thermostat/hardware_controller/raspberry_pi.rb +++ b/lib/thermostat/hardware_controller/raspberry_pi.rb @@ -1,7 +1,7 @@ class Thermostat::HardwareController module RaspberryPi extend Forwardable - include Thermostat::Logger + include Thermostat::Logging autoload :GPIO, File.join('thermostat', 'hardware_controller', 'raspberry_pi', 'gpio') autoload :PinCleaner, File.join('thermostat', 'hardware_controller', 'raspberry_pi', 'pin_cleaner') @@ -11,7 +11,7 @@ module RaspberryPi def initialize_pin(pin, **args) - logger.debug(self.class.name) { "Setting pin #{pin} as #{args[:as]} initialized #{args[:initialize]}" } + logger.hardware(:debug) { "Setting pin #{pin} as #{args[:as]} initialized #{args[:initialize]}" } setup pin, as: args[:as], initialize: args[:initialize] end diff --git a/lib/thermostat/hardware_controller/raspberry_pi/pin_cleaner.rb b/lib/thermostat/hardware_controller/raspberry_pi/pin_cleaner.rb index 7ee1230..9d101c5 100644 --- a/lib/thermostat/hardware_controller/raspberry_pi/pin_cleaner.rb +++ b/lib/thermostat/hardware_controller/raspberry_pi/pin_cleaner.rb @@ -3,7 +3,7 @@ module PinCleaner def clean_up(pin, numbering=:bcm) proc { - Thermostat.logger.debug { "Cleaning raspberry pi pin #{pin}" } + Thermostat.logger.hardware(:debug) { "Cleaning raspberry pi pin #{pin}" } Thermostat::HardwareController::RaspberryPi.gpio.set_numbering numbering Thermostat::HardwareController::RaspberryPi.gpio.clean_up pin } diff --git a/lib/thermostat/hardware_controller/raspberry_pi/relay.rb b/lib/thermostat/hardware_controller/raspberry_pi/relay.rb index a1a5385..8ad981f 100644 --- a/lib/thermostat/hardware_controller/raspberry_pi/relay.rb +++ b/lib/thermostat/hardware_controller/raspberry_pi/relay.rb @@ -5,7 +5,7 @@ class Relay include Thermostat::HardwareController::RaspberryPi def initialize(pin, numbering: :bcm, close_direction: :low) - logger.debug(self.class.name) { "Setting up relay on pin #{pin} (numbering: #{numbering}, close_direction: #{close_direction})" } + logger.hardware(:debug) { "Setting up relay on pin #{pin} (numbering: #{numbering}, close_direction: #{close_direction})" } self.pin = pin self.close_direction = close_direction set_numbering numbering if numbering @@ -36,7 +36,7 @@ def open_direction def toggle(dir) - logger.debug(self.class.name) { "sending set_#{dir} on pin #{pin}" } + logger.hardware(:debug) { "sending set_#{dir} on pin #{pin}" } send "set_#{dir}", pin end diff --git a/lib/thermostat/logger.rb b/lib/thermostat/logger.rb index 303cf6c..1cdf1a7 100644 --- a/lib/thermostat/logger.rb +++ b/lib/thermostat/logger.rb @@ -1,25 +1,157 @@ -require 'brogger' +require 'logger' class Thermostat - module Logger + class Logger < ::Logger - attr_writer :logger + autoload :Formatter, File.join('thermostat', 'logger', 'formatter') - # TODO Implement multi-logger - # http://stackoverflow.com/a/6410202 - def default_logger(level: :warn) - Brogger.new(STDERR).tap do |logger| - logger.level = level - logger.progname = :thermostat + module Subsystem + HARDWARE = 0 # Raspberry Pi / microcontroller information + STATE_MACHINE = 1 # State changes + CONTROLLER = 2 # Hardware controller messages + SENSOR = 3 # Temperature, humidity, etc + THERMOSTAT = 4 # General operation messages + end + include Subsystem + + # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN + SEVERITY_MAPPING = { debug: DEBUG, # Low-level information for developers + error: ERROR, # A handleable error condition + fatal: FATAL, # An unhandleable error that results in a program crash + info: INFO, # Generic (useful) information about system operation + unknown: UNKNOWN, # An unknown message that should always be logged + warn: WARN # A warning + } + + # HARDWARE < STATE_MACHINE < CONTROLLER < SENSOR < THERMOSTAT + SUBSYSTEM_MAPPING = { controller: CONTROLLER, + hartware: HARDWARE, + thermostat: THERMOSTAT, + sensor: SENSOR, + state_machine: STATE_MACHINE + } + + attr_reader :subsystem + + def add(severity, subsystem, message=nil) + severity = lookup_severity(severity) + subsystem = lookup_subsystem(subsystem) + if @logdev.nil? or (severity < @level and subsystem < @subsystem) + return true + end + if message.nil? && block_given? + message = yield end + if message.nil? + false + else + @logdev.write format_message(format_severity(severity), format_subsystem(subsystem), Time.now, message ) + true + end + end + + + def controller(severity=nil, msg=nil, &block) + add severity, CONTROLLER, msg, &block + end + + + def debug(subsystem=nil, msg=nil, &block) + add DEBUG, subsystem, msg, &block + end + + + def error(subsystem=nil, msg=nil, &block) + add ERROR, subsystem, msg, &block + end + + + def fatal(subsystem=nil, msg=nil, &block) + add FATAL, subsystem, msg, &block + end + + + def format_message(severity, subsystem, time, message) + @formatter.call(severity, subsystem, time, @progname, message) + end + + + + def hardware(severity=nil, msg=nil, &block) + add severity, HARDWARE, msg, &block + end + + + def info(subsystem=nil, msg=nil, &block) + add INFO, subsystem, msg, &block + end + + + def initialize(*) + super + self.formatter = Formatter.new + @subsystem = THERMOSTAT + end + + + def level=(l) + super lookup_severity(l) + end + + + def sensor(severity=nil, msg=nil, &block) + add severity, SENSOR, msg, &block + end + + + def state_machine(severity=nil, msg=nil, &block) + add severity, STATE_MACHINE, msg, &block + end + + + def subsystem=(s) + @subsystem = lookup_subsystem(s) + end + + + def thermostat(severity=nil, msg=nil, &block) + add severity, THERMOSTAT, msg, &block + end + + + def unknown(subsystem=nil, msg=nil, &block) + add UNKNOWN, subsystem, msg, &block + end + + + def warn(subsystem=nil, msg=nil, &block) + add WARN, subsystem, msg, &block + end + + private + + SUBSYSTEM_LABEL = %w(HARDWARE STATE_MACHINE CONTROLLER SENSOR THERMOSTAT ANY).each(&:freeze).freeze + + def severity_mapping; SEVERITY_MAPPING; end + def subsystem_mapping; SUBSYSTEM_MAPPING; end + + + def format_subsystem(s) + SUBSYSTEM_LABEL[s] || SUBSYSTEM_LEVEL[-1] + end + + + def lookup_severity(s) + lookup(s, severity_mapping, UNKNOWN) + end + + + def lookup_subsystem(s) + lookup(s, subsystem_mapping, THERMOSTAT) end - def logger - @logger ||= if self == Thermostat - default_logger - else - Thermostat.logger - end + def lookup(s,m,d) + s.is_a?(Integer) ? s : m.fetch(s.to_s.downcase.intern, d) end end diff --git a/lib/thermostat/logger/formatter.rb b/lib/thermostat/logger/formatter.rb new file mode 100644 index 0000000..39ed70c --- /dev/null +++ b/lib/thermostat/logger/formatter.rb @@ -0,0 +1,20 @@ +class Thermostat::Logger + class Formatter < ::Logger::Formatter + + def call(severity, subsystem, time, progname, msg) + format % [ time.utc.iso8601, progname, $$, subsystem, severity, msg2str(msg) ] + end + + + def format + # time [progname.pid] subsystem.severity: msg + "%s [%s.%d] %13s.%5s: %s\n" + end + + + def msg2str(*) + super.strip + end + + end +end diff --git a/lib/thermostat/logging.rb b/lib/thermostat/logging.rb new file mode 100644 index 0000000..b06aa95 --- /dev/null +++ b/lib/thermostat/logging.rb @@ -0,0 +1,23 @@ +class Thermostat + module Logging + + # TODO Implement multi-logger + # http://stackoverflow.com/a/6410202 + def self.default_logger(level: :warn) + Thermostat::Logger.new(STDERR).tap do |logger| + logger.level = level + logger.progname = :thermostat + end + end + + + def logger + @logger ||= if self == Thermostat + Thermostat::Logging.default_logger + else + Thermostat.logger + end + end + + end +end diff --git a/lib/thermostat/logging_adapter.rb b/lib/thermostat/logging_adapter.rb index 5086322..b2b7319 100644 --- a/lib/thermostat/logging_adapter.rb +++ b/lib/thermostat/logging_adapter.rb @@ -1,12 +1,12 @@ require 'statesman' class Thermostat class LoggingAdapter < Statesman::Adapters::Memory - include Thermostat::Logger + include Thermostat::Logging def create(from, to, metadata={}) - logger.debug(@parent_model) { "Beginning transition from #{from} to #{to}" } + logger.state_machine(:debug) { "Beginning transition from #{from} to #{to}" } t = super - logger.debug(@parent_model) { "Finished transition from #{from} to #{to}" } + logger.state_machine(:debug) { "Finished transition from #{from} to #{to}" } t end diff --git a/lib/thermostat/sensor/temperature.rb b/lib/thermostat/sensor/temperature.rb index 51937b4..ad2c213 100644 --- a/lib/thermostat/sensor/temperature.rb +++ b/lib/thermostat/sensor/temperature.rb @@ -43,7 +43,7 @@ def unitify_temp(t) else m = "don't know how to handle a #{t.class} temperature" if defined? logger - logger.warn m + logger.sensor(:error) { m } return nil else raise m diff --git a/lib/thermostat/simple.rb b/lib/thermostat/simple.rb index 9157fe6..e3f5329 100644 --- a/lib/thermostat/simple.rb +++ b/lib/thermostat/simple.rb @@ -1,66 +1,41 @@ class Thermostat class Simple # Basic 4 and 5-wire thermostats - include Thermostat::Logger + include Thermostat::Logging + autoload :Controller, File.join('thermostat', 'simple', 'controller') autoload :StateMachine, File.join('thermostat', 'simple', 'state_machine') attr_accessor :name + attr_reader :controller, :state_machine - def initialize(cooling_controller: nil, fanning_controller: nil, heating_controller: nil, name: nil) - self.name = name - self.cooling_controller = cooling_controller - self.fanning_controller = fanning_controller - self.heating_controller = heating_controller - self.state_machine = StateMachine.new self + def initialize(controller:, name: nil) + self.name = name || "Simple Thermostat" + self.controller = controller + self.state_machine = StateMachine.new(self.controller) + self.controller.state_machine = self.state_machine end - def cool; switch_to :cooling; end - def cooldown; switch_to :cooldown; end - def heat; switch_to :heating; end - def off; switch_to :idle; end + def cooldown; switch_to :cooldown; end - def cooldown_passed? - true - end + def heat; switch_to :heating; end + def off; switch_to :idle; end - def toggle(switch) - case switch - when :cooldown - fanning_controller.on - cooling_controller.off - heating_controller.off - when :cooling - fanning_controller.on - cooling_controller.on - heating_controller.off - when :heating - fanning_controller.on - cooling_controller.off - heating_controller.on - when :idle - fanning_controller.off - cooling_controller.off - heating_controller.off - else - logger.error(self.class.name) { "Don't know how to toggle #{switch} to #{state}" } - end - end private - attr_accessor :cooling_controller, :fanning_controller, :heating_controller, :state_machine + attr_writer :controller, :state_machine def switch_to(setting) - logger.debug(self.class.name) { "Switching to #{setting}" } + logger.controller(:debug) { "Switching to #{setting}" } if( state_machine.can_transition_to? setting ) state_machine.transition_to(setting) else - logger.debug(self.class.name) { "State machine won't allow it" } + logger.controller(:debug) { "State machine won't allow it" } end end diff --git a/lib/thermostat/simple/controller.rb b/lib/thermostat/simple/controller.rb new file mode 100644 index 0000000..1c37924 --- /dev/null +++ b/lib/thermostat/simple/controller.rb @@ -0,0 +1,67 @@ +class Thermostat::Simple + class Controller + include Thermostat::Logging + + attr_accessor :state_machine + + def initialize(cool_relay:, fan_relay:, heat_relay:, cooldown_seconds: 120) + self.cool_relay = cool_relay + self.fan_relay = fan_relay + self.heat_relay = heat_relay + self.cooldown_seconds = cooldown_seconds + end + + + def cooldown_passed? + if cooldown_enter_time + (Time.now - cooldown_enter_time) > cooldown_seconds + else + true + end + end + + + def toggle(switch) + case switch + when :cooldown + fan_relay.on + cool_relay.off + heat_relay.off + when :cooling + fan_relay.on + cool_relay.on + heat_relay.off + when :fanning + fan_relay.on + cool_relay.off + heat_relay.off + when :heating + fan_relay.on + cool_relay.off + heat_relay.on + when :idle + fan_relay.off + cool_relay.off + heat_relay.off + else + logger.controller(:error) { "Don't know how to toggle #{switch} to #{state}" } + end + end + + + private + + attr_accessor :cool_relay, :cooldown_seconds, :fan_relay, :heat_relay + + def cooldown_state + "cooldown".freeze + end + + + def cooldown_enter_time + state_machine.history.select { |t| t.to_state == cooldown_state }.collect(&:created_at).last + end + + + end +end diff --git a/lib/thermostat/simple/state_machine.rb b/lib/thermostat/simple/state_machine.rb index 54e7b09..dd86a79 100644 --- a/lib/thermostat/simple/state_machine.rb +++ b/lib/thermostat/simple/state_machine.rb @@ -14,12 +14,13 @@ class StateMachine transition from: :idle, to: [ :cooling, :fanning, :heating ] transition from: :cooling, to: [ :cooldown ] transition from: :cooldown, to: [ :cooling, :fanning, :heating, :idle ] + transition from: :fanning, to: [ :idle ] transition from: :heating, to: [ :cooldown ] - def initialize(object, options = { transition_class: Statesman::Adapters::MemoryTransition }) + def initialize(controller, options = { transition_class: Statesman::Adapters::MemoryTransition }) super - @storage_adapter = LoggingAdapter.new( @transition_class, object, self, options) + @storage_adapter = LoggingAdapter.new( @transition_class, controller, self, options) end diff --git a/lib/thermostat/zone.rb b/lib/thermostat/zone.rb index 90130ad..9ddbde7 100644 --- a/lib/thermostat/zone.rb +++ b/lib/thermostat/zone.rb @@ -1,7 +1,7 @@ class Thermostat class Zone - include Logger + include Logging attr_reader :config, :fan, :name, :sensors, :set_point, :thermostat @@ -15,7 +15,7 @@ def initialize(**args) self.sensors = args[:sensors] self.thermostat = args[:thermostat] self.set_point = args[:set_point] - logger.debug "zone #{self.name} initialized" + logger.thermostat(:debug) { "zone #{self.name} initialized" } end diff --git a/spec/cases/thermostat/logger/formatter_spec.rb b/spec/cases/thermostat/logger/formatter_spec.rb new file mode 100644 index 0000000..62cbfb0 --- /dev/null +++ b/spec/cases/thermostat/logger/formatter_spec.rb @@ -0,0 +1,3 @@ +describe Thermostat::Logger::Formatter do + +end diff --git a/spec/cases/thermostat/logger_spec.rb b/spec/cases/thermostat/logger_spec.rb index c596617..c5076a6 100644 --- a/spec/cases/thermostat/logger_spec.rb +++ b/spec/cases/thermostat/logger_spec.rb @@ -1,21 +1,45 @@ describe Thermostat::Logger do - let(:klass) { Class.new { include Thermostat::Logger } } - let(:logger) { subject.logger } - let(:subject) { klass.new } + let(:logdev) { $stdout } + let(:subject) { described_class.new logdev } - it 'has a logger' do - expect(logger).not_to be_nil - end + context 'changing levels with a symbol' do + + described_class.const_get(:SEVERITY_MAPPING).each_pair do |sym, level| + it "changes level to #{sym}" do + expect(subject.level).not_to eq sym + subject.level = sym + expect(subject.level).to eq level + end + end + it 'uses UNKNOWN when the symbol is unrecognized' do + sym = :blark + expect(described_class.const_get(:SEVERITY_MAPPING).has_key?(sym)).to be_falsey + subject.level = sym + expect( subject.level).to eq described_class.const_get(:UNKNOWN) + end - it 'has a logger writer' do - expect(subject).to respond_to :logger= end - it 'uses Therrmostat#logger' do - expect(logger).to eq Thermostat.logger - end + context 'changing subsystems with a symbol' do + + described_class.const_get(:SUBSYSTEM_MAPPING).each_pair do |sym, level| + it "changes subsystem to #{sym}" do + expect(subject.subsystem).not_to eq sym + subject.subsystem = sym + expect(subject.subsystem).to eq level + end + end + + it 'uses THERMOSTAT when the symbol is unrecognized' do + sym = :blark + expect(described_class.const_get(:SUBSYSTEM_MAPPING).has_key?(sym)).to be_falsey + subject.subsystem = sym + expect( subject.subsystem).to eq described_class.const_get(:THERMOSTAT) + end + + end end diff --git a/spec/cases/thermostat/logging_spec.rb b/spec/cases/thermostat/logging_spec.rb new file mode 100644 index 0000000..3999de3 --- /dev/null +++ b/spec/cases/thermostat/logging_spec.rb @@ -0,0 +1,30 @@ +describe Thermostat::Logging do + + context 'class-level logger' do + let(:logger) { described_class.default_logger } + + it 'has a default_logger' do + expect(logger).not_to be_nil + end + + it 'is a Brogger' do + expect(logger).to be_a Thermostat::Logger + end + + end + + + let(:klass) { Class.new { include Thermostat::Logging } } + let(:logger) { subject.logger } + let(:subject) { klass.new } + + it 'has a logger' do + expect(logger).not_to be_nil + end + + + it 'uses Therrmostat#logger' do + expect(logger).to eq Thermostat.logger + end + +end diff --git a/spec/cases/thermostat/simple/controller_spec.rb b/spec/cases/thermostat/simple/controller_spec.rb new file mode 100644 index 0000000..b8db839 --- /dev/null +++ b/spec/cases/thermostat/simple/controller_spec.rb @@ -0,0 +1,8 @@ +describe Thermostat::Simple::Controller do + + let(:cool_relay) { double :cool_relay } + let(:fan_relay) { double :fan_relay } + let(:heat_relay) { double :heat_relay } + let(:subject) { described_class.new cool_relay: cool_relay, fan_relay: fan_relay, heat_relay: heat_relay } + +end diff --git a/spec/cases/thermostat_spec.rb b/spec/cases/thermostat_spec.rb index ad5a882..573a78c 100644 --- a/spec/cases/thermostat_spec.rb +++ b/spec/cases/thermostat_spec.rb @@ -15,13 +15,7 @@ it 'has a class-level logger' do - expect(described_class.logger).to be_a Brogger - end - - - it 'allows you to change the class-level logger' do - described_class.logger = :llama - expect(described_class.logger).to eq :llama + expect(described_class.logger).to be_a Thermostat::Logger end diff --git a/thermostat.gemspec b/thermostat.gemspec index 0e480dc..c7c9574 100644 --- a/thermostat.gemspec +++ b/thermostat.gemspec @@ -4,19 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'thermostat/version' Gem::Specification.new do |spec| - spec.name = "thermostat" - spec.version = Thermostat.version - spec.authors = ["Dean Brundage"] - spec.email = ["github@deanandadie.net"] + spec.name = "thermostat" + spec.version = Thermostat.version + spec.authors = ["Dean Brundage"] + spec.email = ["github@deanandadie.net"] - spec.summary = %q{A thermostat gem} - spec.description = %q{For controlling a thermostat} - spec.homepage = "https://github.com/brundage/thermostat" + spec.summary = %q{A thermostat gem} + spec.description = %q{For controlling a thermostat} + spec.homepage = "https://github.com/brundage/thermostat" + spec.license = 'AGPL-3.0' - spec.files = `git ls-files -z`.split("\x0").reject do |f| + spec.required_ruby_version = '>= 2.1' + + spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^spec/cases}) end - spec.bindir = "exe" + + spec.bindir = "bin" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] @@ -26,10 +30,9 @@ Gem::Specification.new do |spec| spec.add_development_dependency "guard-rspec" spec.add_development_dependency "coveralls" - spec.add_dependency 'brogger' - spec.add_dependency 'statesman' - spec.add_dependency 'ruby_i2c' - spec.add_dependency 'ruby-units' - spec.add_dependency 'rpi_gpio' + spec.add_runtime_dependency 'statesman' + spec.add_runtime_dependency 'ruby_i2c' + spec.add_runtime_dependency 'ruby-units' + spec.add_runtime_dependency 'rpi_gpio' end