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_labels(sensor) ⇒ Object
- #sensor_timeseries(sensor, opts = {}) ⇒ Object
- #sensors ⇒ Object
Instance Method Details
#create_sensor(attributes) ⇒ Object
60 61 62 |
# File 'lib/helium/client/sensors.rb', line 60 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
33 34 35 36 37 38 39 |
# File 'lib/helium/client/sensors.rb', line 33 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_labels(sensor) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/helium/client/sensors.rb', line 21 def sensor_labels(sensor) path = "/sensor/#{sensor.id}/label" response = get(path) labels_data = JSON.parse(response.body)["data"] labels = labels_data.map do |label| Label.new(client: self, params: label) end return labels end |
#sensor_timeseries(sensor, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/helium/client/sensors.rb', line 41 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 |