module Helium::Client::Sensors
Public Instance Methods
create_sensor(attributes)
click to toggle source
# File lib/helium/client/sensors.rb, line 62 def create_sensor(attributes) Sensor.create(attributes, client: self) end
sensor(id)
click to toggle source
# File lib/helium/client/sensors.rb, line 8 def sensor(id) Sensor.find(id, client: self) end
sensor_device_configuration(sensor)
click to toggle source
# File lib/helium/client/sensors.rb, line 21 def sensor_device_configuration(sensor) path = "/sensor/#{sensor.id}/device-configuration" response = get(path) dc_data = JSON.parse(response.body)["data"] # dc_data is an array, but there will only be one for one return DeviceConfiguration.new(client: self, params: dc_data[0]) end
sensor_element(sensor)
click to toggle source
# File lib/helium/client/sensors.rb, line 12 def sensor_element(sensor) path = "/sensor/#{sensor.id}/element" response = get(path) elementj = JSON.parse(response.body)["data"] element = Element.new(client: self, params: elementj) return element end
sensor_live_timeseries(sensor, opts = {}, &block)
click to toggle source
# File lib/helium/client/sensors.rb, line 48 def sensor_live_timeseries(sensor, opts = {}, &block) path = "/sensor/#{sensor.id}/timeseries/live" params = { "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? } stream_from(path, klass: Helium::DataPoint, params: params, &block) end
sensor_timeseries(sensor, opts = {})
click to toggle source
# File lib/helium/client/sensors.rb, line 29 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, cursor_klass: Helium::Timeseries, params: params ) end
sensors()
click to toggle source
# File lib/helium/client/sensors.rb, line 4 def sensors Sensor.all(client: self) end