Class: Helium::Sensor

Inherits:
Resource show all
Defined in:
lib/helium/sensor.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #type

Instance Method Summary collapse

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
12
13
14
# 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')
  @firmware  = @params.dig('meta', 'versions', 'sensor')

end

Instance Attribute Details

#firmwareObject (readonly)

Returns the value of attribute firmware



3
4
5
# File 'lib/helium/sensor.rb', line 3

def firmware
  @firmware
end

#last_seenDateTime? (readonly)

Returns when the resource was last seen

Returns:

  • (DateTime, nil)

    when the resource was last seen



35
36
37
# File 'lib/helium/sensor.rb', line 35

def last_seen
  @last_seen
end

#macObject (readonly)

Returns the value of attribute mac



3
4
5
# File 'lib/helium/sensor.rb', line 3

def mac
  @mac
end

#nameObject (readonly)

Returns the value of attribute name



3
4
5
# File 'lib/helium/sensor.rb', line 3

def name
  @name
end

#portsObject (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_jsonObject

TODO can probably generalize this a bit more



41
42
43
44
45
46
47
48
49
# File 'lib/helium/sensor.rb', line 41

def as_json
  super.merge({
    name: name,
    mac: mac,
    ports: ports,
    last_seen: last_seen,
    firmware: firmware
  })
end

#timeseries(opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/helium/sensor.rb', line 16

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