Class: Helium::Sensor

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Instance Method Summary collapse

Methods inherited from Resource

#==, #created_at, #eql?, #hash, #to_json, #updated_at

Constructor Details

#initialize(client:, params:) ⇒ Sensor

Returns a new instance of Sensor



5
6
7
8
9
10
11
# File 'lib/helium/sensor.rb', line 5

def initialize(client:, params:)
  super(client: client, params: params)

  @name  = params.dig('attributes', 'name')
  @mac   = params.dig('meta', 'mac')
  @ports = params.dig('meta', 'ports')
end

Instance Attribute Details

#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



34
35
36
37
38
39
40
# File 'lib/helium/sensor.rb', line 34

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

#destroyObject



29
30
31
# File 'lib/helium/sensor.rb', line 29

def destroy
  @client.delete_sensor(self)
end

#timeseries(size: 1000, port: nil, start_time: nil, end_time: nil, aggtype: nil, aggsize: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/helium/sensor.rb', line 13

def timeseries(size: 1000, port: nil, start_time: nil, end_time: nil, aggtype: nil, aggsize: nil)
  @client.sensor_timeseries(self,
    size:       size,
    port:       port,
    start_time: start_time,
    end_time:   end_time,
    aggtype:    aggtype,
    aggsize:    aggsize
  )
end

#update(name:) ⇒ Object

TODO CRUD methods will be generalized into the Resource object



25
26
27
# File 'lib/helium/sensor.rb', line 25

def update(name:)
  @client.update_sensor(self, name: name)
end