Sha256: 214cb2850557aceb2e64f3b55464dfbeee2854165f6629d44e018f1cbd724db8

Contents?: true

Size: 736 Bytes

Versions: 3

Compression:

Stored size: 736 Bytes

Contents

require 'w1temp'

module MilkMaid
  class SensorException < RuntimeError; end

  class TemperatureSensor
    def initialize
      @sensor = Temperature.new

      fail ::MilkMaid::SensorException.new 'Sensor not available' unless @sensor.name
    end

    def name
      return "No sensor attached" unless @sensor.name
      @sensor.name
    end

    def reading
      return "Reading: No sensor attached" unless @sensor.reading
      @sensor.reading.to_f
    end
  end

  class MockTemperatureSensor
    def initialize(low_temp, high_temp)
      @low_temp = low_temp.to_i
      @high_temp = high_temp.to_i
    end

    def name
      'MockTemperatureSensor'
    end

    def reading
      rand(@low_temp..@high_temp)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
milk_maid-0.6.1 lib/milk_maid/temperature_sensor.rb
milk_maid-0.5.1 lib/milk_maid/temperature_sensor.rb
milk_maid-0.5.0 lib/milk_maid/temperature_sensor.rb