Module: Helium::Client::Sensors
- Included in:
- Helium::Client
- Defined in:
- lib/helium/client/sensors.rb
Instance Method Summary collapse
- #create_sensor(attributes) ⇒ Object
- #sensor(id) ⇒ Object
- #sensor_device_configuration(sensor) ⇒ Object
- #sensor_element(sensor) ⇒ Object
- #sensor_live_timeseries(sensor, opts = {}, &block) ⇒ Object
- #sensor_timeseries(sensor, opts = {}) ⇒ Object
- #sensors ⇒ Object
Instance Method Details
#create_sensor(attributes) ⇒ Object
62 63 64 |
# File 'lib/helium/client/sensors.rb', line 62 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_device_configuration(sensor) ⇒ Object
21 22 23 24 25 26 27 |
# 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) ⇒ Object
12 13 14 15 16 17 18 19 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |