Sha256: b27a1a6e74d9d0363090255dd5c1913e4f1bc736697ee82fe12d9f4db8d49433

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 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.display
      @sensor.name
    end

    def reading
      return "Reading: No sensor attached" unless @sensor.display
      @sensor.reading
    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

1 entries across 1 versions & 1 rubygems

Version Path
milk_maid-0.1.0 lib/milkmaid/temperature_sensor.rb