Class: Helium::Sensor
Instance Attribute Summary collapse
-
#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
Instance Method Summary collapse
-
#as_json ⇒ Object
TODO can probably generalize this a bit more.
-
#initialize(opts = {}) ⇒ Sensor
constructor
A new instance of Sensor.
- #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 |
# 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') end |
Instance Attribute Details
#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 |
Instance Method Details
#as_json ⇒ Object
TODO can probably generalize this a bit more
32 33 34 35 36 37 38 |
# File 'lib/helium/sensor.rb', line 32 def as_json super.merge({ name: name, mac: mac, ports: ports }) end |
#timeseries(opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/helium/sensor.rb', line 13 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 |