Class: Helium::Sensor
Instance Attribute Summary collapse
-
#last_seen ⇒ DateTime?
readonly
When the resource was last seen.
-
#mac ⇒ Object
readonly
Returns the value of attribute mac.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json ⇒ Object
TODO can probably generalize this a bit more.
- #element ⇒ Object
-
#initialize(opts = {}) ⇒ Sensor
constructor
A new instance of Sensor.
-
#labels ⇒ Object
NOTE: currently this just returns the ids of labels.
- #timeseries(opts = {}) ⇒ Object
Methods inherited from Resource
#==, all, create, #created_at, #destroy, #eql?, find, #hash, #to_json, #update, #updated_at
Constructor Details
#initialize(opts = {}) ⇒ Sensor
Returns a new instance of Sensor.
5 6 7 8 9 10 11 12 |
# 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') end |
Instance Attribute Details
#last_seen ⇒ DateTime? (readonly)
Returns when the resource was last seen.
51 52 53 |
# File 'lib/helium/sensor.rb', line 51 def last_seen @last_seen end |
#mac ⇒ Object (readonly)
Returns the value of attribute mac.
3 4 5 |
# File 'lib/helium/sensor.rb', line 3 def mac @mac end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/helium/sensor.rb', line 3 def name @name end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
3 4 5 |
# File 'lib/helium/sensor.rb', line 3 def ports @ports end |
Class Method Details
.all_path ⇒ Object
18 19 20 |
# File 'lib/helium/sensor.rb', line 18 def self.all_path "/sensor?include=label" end |
Instance Method Details
#as_json ⇒ Object
TODO can probably generalize this a bit more
57 58 59 60 61 62 63 64 65 |
# File 'lib/helium/sensor.rb', line 57 def as_json super.merge({ name: name, mac: mac, ports: ports, last_seen: last_seen, labels: labels }) end |
#element ⇒ Object
14 15 16 |
# File 'lib/helium/sensor.rb', line 14 def element @client.sensor_element(self) end |
#labels ⇒ Object
NOTE: currently this just returns the ids of labels. Once core returns all label info via includes=label, we can get rid of the label_relationships stuff
25 26 27 28 29 30 |
# File 'lib/helium/sensor.rb', line 25 def labels labels_params = Array(@params.dig('relationships', 'label', 'data')) @labels ||= labels_params.map{ |label_params| Label.new(client: @client, params: label_params) } end |
#timeseries(opts = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/helium/sensor.rb', line 32 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 |