Class: TempoIQ::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/tempoiq/models/device.rb

Overview

The top level container for a group of sensors.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, name = "", attributes = {}, *sensors) ⇒ Device

Returns a new instance of Device.



19
20
21
22
23
24
# File 'lib/tempoiq/models/device.rb', line 19

def initialize(key, name = "", attributes = {}, *sensors)
  @key = key
  @name = name
  @attributes = attributes
  @sensors = sensors
end

Instance Attribute Details

#attributesObject

Indexable attributes. Useful for grouping related Devices. EG - => ‘445-w-Erie’, ‘model’ => ‘TX75’, ‘region’ => ‘Southwest’



14
15
16
# File 'lib/tempoiq/models/device.rb', line 14

def attributes
  @attributes
end

#keyObject (readonly)

The primary key of the device [String]



7
8
9
# File 'lib/tempoiq/models/device.rb', line 7

def key
  @key
end

#nameObject

Human readable name of the device [String] EG - “My Device”



10
11
12
# File 'lib/tempoiq/models/device.rb', line 10

def name
  @name
end

#sensorsObject

Sensors attached to the device [Array] (Sensor)



17
18
19
# File 'lib/tempoiq/models/device.rb', line 17

def sensors
  @sensors
end

Class Method Details

.from_hash(hash) ⇒ Object



26
27
28
29
# File 'lib/tempoiq/models/device.rb', line 26

def self.from_hash(hash)
  new(hash['key'], hash['name'], hash['attributes'],
      *hash['sensors'].map { |s| Sensor.new(s['key'], s['name'], s['attributes']) })
end

Instance Method Details

#to_hashObject



31
32
33
34
35
36
37
38
# File 'lib/tempoiq/models/device.rb', line 31

def to_hash
  {
    'key' => key,
    'name' => name,
    'attributes' => attributes,
    'sensors' => sensors.map(&:to_hash)
  }
end