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.
- #device_configuration ⇒ Object
- #element ⇒ Object
-
#initialize(opts = {}) ⇒ Sensor
constructor
A new instance of Sensor.
- #labels ⇒ Object
- #live_timeseries(opts = {}, &block) ⇒ Object
- #timeseries(opts = {}) ⇒ Object
- #virtual? ⇒ Boolean
Methods inherited from Resource
#==, all, create, #created_at, #destroy, #eql?, find, #hash, initialize_from_path, #metadata, resource_name, #resource_name, #resource_path, singleton, #to_json, #update, #updated_at
Methods included from Utils
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
69 70 71 |
# File 'lib/helium/sensor.rb', line 69 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
75 76 77 78 79 80 81 82 83 |
# File 'lib/helium/sensor.rb', line 75 def as_json super.merge({ name: name, mac: mac, ports: ports, last_seen: last_seen, virtual: virtual? }) end |
#device_configuration ⇒ Object
26 27 28 |
# File 'lib/helium/sensor.rb', line 26 def device_configuration @client.sensor_device_configuration(self) end |
#element ⇒ Object
14 15 16 |
# File 'lib/helium/sensor.rb', line 14 def element @client.sensor_element(self) end |
#labels ⇒ Object
22 23 24 |
# File 'lib/helium/sensor.rb', line 22 def labels Collection.new(klass: Label, client: @client, belongs_to: self) end |
#live_timeseries(opts = {}, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/helium/sensor.rb', line 52 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 |
#timeseries(opts = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/helium/sensor.rb', line 34 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? ⇒ Boolean
30 31 32 |
# File 'lib/helium/sensor.rb', line 30 def virtual? mac.nil? end |