Class: Tinkerforge::BrickletOutdoorWeather

Inherits:
Object
  • Object
show all
Defined in:
lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb

Instance Method Summary collapse

Instance Method Details

#sensorsObject

Returns the last measured data for all sensors.

The result is a Hash, with sensor identifiers (or their mapped values) as the keys. Values per sensor are:

  • 0: Temperature (°C)

  • 1: Relative humidity (%RH)

  • 2: Last change (seconds)

Sensor identifiers can be mapped to descriptive strings or other values:

Examples:

my_weather_bricklet.config['sensormap'] = { 202 => 'outdoors' }


22
23
24
25
26
27
# File 'lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb', line 22

def sensors
  sensormap = (config['sensormap'].class == Hash) ? config['sensormap'] : {}
  get_sensor_identifiers.map do |id|
    [ (sensormap[id] || id), get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
  end.to_h
end

#stateObject

Returns the device’s state.



6
7
8
9
10
# File 'lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb', line 6

def state
  super.merge(
    'sensor_data' => sensors,
  )
end