Class: Helium::Element
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.
Attributes inherited from Resource
Instance Method Summary collapse
-
#as_json ⇒ Object
TODO can probably generalize this a bit more.
- #device_configuration ⇒ Object
-
#initialize(opts = {}) ⇒ Element
constructor
A new instance of Element.
- #sensors ⇒ Object
- #timeseries(opts = {}) ⇒ Object
Methods inherited from Resource
#==, all, all_path, 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 = {}) ⇒ Element
Returns a new instance of Element
5 6 7 8 9 10 11 |
# File 'lib/helium/element.rb', line 5 def initialize(opts = {}) super(opts) @name = @params.dig("attributes", "name") @mac = @params.dig("meta", "mac") @last_seen = @params.dig('meta', 'last-seen') end |
Instance Attribute Details
#last_seen ⇒ DateTime? (readonly)
Returns when the resource was last seen
22 23 24 |
# File 'lib/helium/element.rb', line 22 def last_seen @last_seen end |
#mac ⇒ Object (readonly)
Returns the value of attribute mac
3 4 5 |
# File 'lib/helium/element.rb', line 3 def mac @mac end |
#name ⇒ Object (readonly)
Returns the value of attribute name
3 4 5 |
# File 'lib/helium/element.rb', line 3 def name @name end |
Instance Method Details
#as_json ⇒ Object
TODO can probably generalize this a bit more
28 29 30 31 32 33 34 |
# File 'lib/helium/element.rb', line 28 def as_json super.merge({ name: name, mac: mac, last_seen: last_seen }) end |
#device_configuration ⇒ Object
17 18 19 |
# File 'lib/helium/element.rb', line 17 def device_configuration @client.element_device_configuration(self) end |
#sensors ⇒ Object
13 14 15 |
# File 'lib/helium/element.rb', line 13 def sensors Collection.new(klass: Sensor, client: @client, belongs_to: self) end |
#timeseries(opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/helium/element.rb', line 36 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.element_timeseries(self, size: size, port: port, start_time: start_time, end_time: end_time, aggtype: aggtype, aggsize: aggsize ) end |