Class: ActiveSensor::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_sensor/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(equipment, parameters = {}) ⇒ Connection

Returns a new instance of Connection.


5
6
7
8
9
10
11
12
13
14
# File 'lib/active_sensor/connection.rb', line 5

def initialize(equipment, parameters = {})
  @equipment = equipment
  if equipment.controller
    @controller = equipment.controller.new
    @parameters = {}.with_indifferent_access
    equipment.parameters.each do |name, parameter|
      @parameters[name] = parameter.normalize!(parameters[name.to_s])
    end
  end
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller


3
4
5
# File 'lib/active_sensor/connection.rb', line 3

def controller
  @controller
end

#equipmentObject

Returns the value of attribute equipment


3
4
5
# File 'lib/active_sensor/connection.rb', line 3

def equipment
  @equipment
end

#parametersObject

Returns the value of attribute parameters


3
4
5
# File 'lib/active_sensor/connection.rb', line 3

def parameters
  @parameters
end

Instance Method Details

#retrieve(options = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_sensor/connection.rb', line 16

def retrieve(options = {})
  unless controller
    return { status: :error, message: "No controller given for #{equipment.unique_name}" }
  end
  begin
    report = @controller.retrieve(parameters, options)
  rescue StandardError => e
    raise e
    report = { status: :controller_error, message: e.message }
  end
  report
end