Class: RSMP::ComponentBase

Inherits:
Object
  • Object
show all
Includes:
Inspect
Defined in:
lib/rsmp/component/component_base.rb

Overview

RSMP component base class.

Direct Known Subclasses

Component, ComponentProxy

Constant Summary collapse

AGGREGATED_STATUS_KEYS =
i[local_control
communication_distruption
high_priority_alarm
medium_priority_alarm
low_priority_alarm
normal
rest
not_connected].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:, ntsoid: nil, xnid: nil, grouped: false) ⇒ ComponentBase

Returns a new instance of ComponentBase.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rsmp/component/component_base.rb', line 19

def initialize(node:, id:, ntsoid: nil, xnid: nil, grouped: false)
  if grouped == false && (ntsoid || xnid)
    raise RSMP::ConfigurationError,
          'ntsoid and xnid are only allowed for grouped objects'
  end

  @c_id = id
  @ntsoid = ntsoid
  @xnid = xnid
  @node = node
  @grouped = grouped
  clear_aggregated_status
  @alarms = {}
end

Instance Attribute Details

#aggregated_statusObject (readonly)

Returns the value of attribute aggregated_status.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def aggregated_status
  @aggregated_status
end

#aggregated_status_boolsObject

Returns the value of attribute aggregated_status_bools.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def aggregated_status_bools
  @aggregated_status_bools
end

#alarmsObject (readonly)

Returns the value of attribute alarms.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def alarms
  @alarms
end

#c_idObject (readonly)

Returns the value of attribute c_id.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def c_id
  @c_id
end

#groupedObject (readonly)

Returns the value of attribute grouped.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def grouped
  @grouped
end

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def node
  @node
end

#ntsoidObject (readonly)

Returns the value of attribute ntsoid.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def ntsoid
  @ntsoid
end

#statusesObject (readonly)

Returns the value of attribute statuses.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def statuses
  @statuses
end

#xnidObject (readonly)

Returns the value of attribute xnid.



7
8
9
# File 'lib/rsmp/component/component_base.rb', line 7

def xnid
  @xnid
end

Instance Method Details

#aggregated_status_changed(options = {}) ⇒ Object



85
86
87
# File 'lib/rsmp/component/component_base.rb', line 85

def aggregated_status_changed(options = {})
  @node.aggregated_status_changed self, options
end

#clear_aggregated_statusObject



46
47
48
49
50
# File 'lib/rsmp/component/component_base.rb', line 46

def clear_aggregated_status
  @aggregated_status = []
  @aggregated_status_bools = Array.new(8, false)
  @aggregated_status_bools[5] = true
end

#clear_alarm_timestampsObject



38
39
40
# File 'lib/rsmp/component/component_base.rb', line 38

def clear_alarm_timestamps
  @alarms.each_value(&:clear_timestamp)
end

#get_alarm_state(alarm_code) ⇒ Object



42
43
44
# File 'lib/rsmp/component/component_base.rb', line 42

def get_alarm_state(alarm_code)
  @alarms[alarm_code] ||= RSMP::AlarmState.new component: self, code: alarm_code
end

#log(str, options) ⇒ Object



52
53
54
55
# File 'lib/rsmp/component/component_base.rb', line 52

def log(str, options)
  default = { component: c_id }
  @node.log str, default.merge(options)
end

#nowObject



34
35
36
# File 'lib/rsmp/component/component_base.rb', line 34

def now
  node.now
end

#set_aggregated_status(status, options = {}) ⇒ Object

Raises:

  • (InvalidArgument)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rsmp/component/component_base.rb', line 57

def set_aggregated_status(status, options = {})
  status = [status] if status.is_a? Symbol
  raise InvalidArgument unless status.is_a? Array

  input = status & AGGREGATED_STATUS_KEYS
  return unless input != @aggregated_status

  AGGREGATED_STATUS_KEYS.each_with_index do |key, index|
    @aggregated_status_bools[index] = status.include?(key)
  end
  aggregated_status_changed options
end