class Helium::Element

Attributes

device_type[R]
last_seen[R]
mac[R]
name[R]

Public Class Methods

all_path() click to toggle source
# File lib/helium/element.rb, line 18
def self.all_path
  "/element?include=label"
end
new(opts = {}) click to toggle source
Calls superclass method
# 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')
  @device_type = @params.dig('meta', 'device-type')
end

Public Instance Methods

add_labels(labels_to_add = []) click to toggle source
# File lib/helium/element.rb, line 64
def add_labels(labels_to_add = [])
  # There's no first-class support for modifying the labels of a element in
  # the API yet, so we modify each label's relationship to the element. 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_elements(self)
  end
  self
end
as_json() click to toggle source

TODO can probably generalize this a bit more

Calls superclass method
# File lib/helium/element.rb, line 55
def as_json
  super.merge({
    name: name,
    mac: mac,
    last_seen: last_seen,
    device_type: device_type
  })
end
device_configuration() click to toggle source
# File lib/helium/element.rb, line 26
def device_configuration
  @client.element_device_configuration(self)
end
labels() click to toggle source
# File lib/helium/element.rb, line 22
def labels
  Collection.new(klass: Label, client: @client, belongs_to: self)
end
remove_labels(labels_to_remove = []) click to toggle source
# File lib/helium/element.rb, line 89
def remove_labels(labels_to_remove = [])
  labels_to_remove = Array(labels_to_remove)
  labels_to_remove.each do |label|
    label.remove_elements(self)
  end
  self
end
replace_labels(labels_to_replace = []) click to toggle source
# File lib/helium/element.rb, line 76
def replace_labels(labels_to_replace = [])
  # To support replacement, we remove this element from each label, and then
  # add it to the specified set
  labels_to_replace = Array(labels_to_replace)
  labels.each do |label|
    label.remove_elements(self)
  end
  labels_to_replace.each do |label|
    label.add_elements(self)
  end
  self
end
sensors() click to toggle source
# File lib/helium/element.rb, line 14
def sensors
  Collection.new(klass: Sensor, client: @client, belongs_to: self)
end
timeseries(opts = {}) click to toggle source
# 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