Module: Helium::Client::Sensors

Included in:
Helium::Client
Defined in:
lib/helium/client/sensors.rb

Instance Method Summary collapse

Instance Method Details

#create_sensor(attributes) ⇒ Object



27
28
29
# File 'lib/helium/client/sensors.rb', line 27

def create_sensor(attributes)
  Sensor.create(attributes, client: self)
end

#sensor(id) ⇒ Object



8
9
10
# File 'lib/helium/client/sensors.rb', line 8

def sensor(id)
  Sensor.find(id, client: self)
end

#sensor_timeseries(sensor, opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/helium/client/sensors.rb', line 12

def sensor_timeseries(sensor, opts = {})
  path = "/sensor/#{sensor.id}/timeseries"

  params = {
    "page[size]"    => opts.fetch(:size, nil),
    "filter[port]"  => opts.fetch(:port, nil),
    "filter[start]" => datetime_to_iso(opts.fetch(:start_time, nil)),
    "filter[end]"   => datetime_to_iso(opts.fetch(:end_time, nil)),
    "agg[type]"     => opts.fetch(:aggtype),
    "agg[size]"     => opts.fetch(:aggsize)
  }.delete_if { |_key, value| value.to_s.empty? }

  paginated_get(path, klass: Helium::DataPoint, params: params)
end

#sensorsObject



4
5
6
# File 'lib/helium/client/sensors.rb', line 4

def sensors
  Sensor.all(client: self)
end