Class: Helium::Sensor
Instance Attribute Summary collapse
Attributes inherited from Resource
#id, #params, #type
Class Method Summary
collapse
Instance Method Summary
collapse
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
#datetime_to_iso, #kebab_case
Constructor Details
#initialize(opts = {}) ⇒ Sensor
Returns a new instance of Sensor.
5
6
7
8
9
10
11
12
13
|
# 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')
@device_type = @params.dig('meta', 'device-type')
end
|
Instance Attribute Details
#device_type ⇒ Object
Returns the value of attribute device_type.
3
4
5
|
# File 'lib/helium/sensor.rb', line 3
def device_type
@device_type
end
|
#last_seen ⇒ DateTime?
Returns when the resource was last seen.
70
71
72
|
# File 'lib/helium/sensor.rb', line 70
def last_seen
@last_seen
end
|
#mac ⇒ Object
Returns the value of attribute mac.
3
4
5
|
# File 'lib/helium/sensor.rb', line 3
def mac
@mac
end
|
#name ⇒ Object
Returns the value of attribute name.
3
4
5
|
# File 'lib/helium/sensor.rb', line 3
def name
@name
end
|
#ports ⇒ Object
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
19
20
21
|
# File 'lib/helium/sensor.rb', line 19
def self.all_path
"/sensor?include=label"
end
|
Instance Method Details
#add_labels(labels_to_add = []) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/helium/sensor.rb', line 87
def add_labels(labels_to_add = [])
labels_to_add = Array(labels_to_add)
labels_to_add.each do |label|
label.add_sensors(self)
end
self
end
|
#as_json ⇒ Object
TODO can probably generalize this a bit more
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/helium/sensor.rb', line 76
def as_json
super.merge({
name: name,
mac: mac,
ports: ports,
last_seen: last_seen,
virtual: virtual?,
device_type: device_type
})
end
|
#device_configuration ⇒ Object
27
28
29
|
# File 'lib/helium/sensor.rb', line 27
def device_configuration
@client.sensor_device_configuration(self)
end
|
#element ⇒ Object
15
16
17
|
# File 'lib/helium/sensor.rb', line 15
def element
@client.sensor_element(self)
end
|
#labels ⇒ Object
23
24
25
|
# File 'lib/helium/sensor.rb', line 23
def labels
Collection.new(klass: Label, client: @client, belongs_to: self)
end
|
#live_timeseries(opts = {}, &block) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/helium/sensor.rb', line 53
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
|
#remove_labels(labels_to_remove = []) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/helium/sensor.rb', line 112
def remove_labels(labels_to_remove = [])
labels_to_remove = Array(labels_to_remove)
labels_to_remove.each do |label|
label.remove_sensors(self)
end
self
end
|
#replace_labels(labels_to_replace = []) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/helium/sensor.rb', line 99
def replace_labels(labels_to_replace = [])
labels_to_replace = Array(labels_to_replace)
labels.each do |label|
label.remove_sensors(self)
end
labels_to_replace.each do |label|
label.add_sensors(self)
end
self
end
|
#sensor_packages ⇒ Object
A sensor can be associated with at most 2 sensor-packages: the loaded package and package being loaded
122
123
124
|
# File 'lib/helium/sensor.rb', line 122
def sensor_packages
Collection.new(klass: SensorPackage, client: @client, belongs_to: self)
end
|
#timeseries(opts = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/helium/sensor.rb', line 35
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
31
32
33
|
# File 'lib/helium/sensor.rb', line 31
def virtual?
mac.nil?
end
|