class Helium::Sensor
Attributes
device_type[R]
last_seen[R]
mac[R]
name[R]
ports[R]
Public Class Methods
all_path()
click to toggle source
# File lib/helium/sensor.rb, line 19 def self.all_path "/sensor?include=label" end
new(opts = {})
click to toggle source
Calls superclass method
Helium::Resource::new
# File lib/helium/sensor.rb, line 5 def initialize(opts = {}) super(opts) @name = @params.dig('attributes', 'name') @mac = @params.dig('meta', 'mac') @ports = @params.dig('meta', 'ports') @last_seen = @params.dig('meta', 'last-seen') @device_type = @params.dig('meta', 'device-type') end
Public Instance Methods
add_labels(labels_to_add = [])
click to toggle source
# File lib/helium/sensor.rb, line 87 def add_labels(labels_to_add = []) # There's no first-class support for modifying the labels of a sensor in # the API yet, so we modify each label's relationship to the sensor. Once # this is supported in the API, this can use #add_relationships instead. # Same comment applies for the following 3 functions labels_to_add = Array(labels_to_add) labels_to_add.each do |label| label.add_sensors(self) end self end
as_json()
click to toggle source
TODO can probably generalize this a bit more
Calls superclass method
Helium::Resource#as_json
# File lib/helium/sensor.rb, line 76 def as_json super.merge({ name: name, mac: mac, ports: ports, last_seen: last_seen, virtual: virtual?, device_type: device_type }) end
device_configuration()
click to toggle source
# File lib/helium/sensor.rb, line 27 def device_configuration @client.sensor_device_configuration(self) end
element()
click to toggle source
# File lib/helium/sensor.rb, line 15 def element @client.sensor_element(self) end
labels()
click to toggle source
# File lib/helium/sensor.rb, line 23 def labels Collection.new(klass: Label, client: @client, belongs_to: self) end
live_timeseries(opts = {}, &block)
click to toggle source
# File lib/helium/sensor.rb, line 53 def live_timeseries(opts = {}, &block) port = opts.fetch(:port, nil) start_time = opts.fetch(:start_time, nil) end_time = opts.fetch(:end_time, nil) aggtype = opts.fetch(:aggtype, nil) aggsize = opts.fetch(:aggsize, nil) @client.sensor_live_timeseries(self, { port: port, start_time: start_time, end_time: end_time, aggtype: aggtype, aggsize: aggsize }, &block) end
remove_labels(labels_to_remove = [])
click to toggle source
# File lib/helium/sensor.rb, line 112 def remove_labels(labels_to_remove = []) labels_to_remove = Array(labels_to_remove) labels_to_remove.each do |label| label.remove_sensors(self) end self end
replace_labels(labels_to_replace = [])
click to toggle source
# File lib/helium/sensor.rb, line 99 def replace_labels(labels_to_replace = []) # To support replacement, we remove this sensor from each label, and then # add it to the specified set labels_to_replace = Array(labels_to_replace) labels.each do |label| label.remove_sensors(self) end labels_to_replace.each do |label| label.add_sensors(self) end self end
sensor_packages()
click to toggle source
A sensor can be associated with at most 2 sensor-packages: the loaded package and package being loaded
# File lib/helium/sensor.rb, line 122 def sensor_packages Collection.new(klass: SensorPackage, client: @client, belongs_to: self) end
timeseries(opts = {})
click to toggle source
# File lib/helium/sensor.rb, line 35 def timeseries(opts = {}) size = opts.fetch(:size, 1000) port = opts.fetch(:port, nil) start_time = opts.fetch(:start_time, nil) end_time = opts.fetch(:end_time, nil) aggtype = opts.fetch(:aggtype, nil) aggsize = opts.fetch(:aggsize, nil) @client.sensor_timeseries(self, size: size, port: port, start_time: start_time, end_time: end_time, aggtype: aggtype, aggsize: aggsize ) end
virtual?()
click to toggle source
# File lib/helium/sensor.rb, line 31 def virtual? mac.nil? end