Class: RSMP::ComponentBase

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(node:, id:, **attributes) ⇒ ComponentBase

Returns a new instance of ComponentBase.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rsmp/component/component_base.rb', line 16

def initialize(node:, id:, **attributes)
  type = attributes[:type]
  name = attributes[:name]
  ntsoid = attributes[:ntsoid]
  xnid = attributes[:xnid]
  grouped = attributes.fetch(:grouped, false)

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

  @c_id = id
  @component_type = type
  @name = name || 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.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def aggregated_status
  @aggregated_status
end

#aggregated_status_boolsObject

Returns the value of attribute aggregated_status_bools.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def aggregated_status_bools
  @aggregated_status_bools
end

#alarmsObject (readonly)

Returns the value of attribute alarms.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def alarms
  @alarms
end

#c_idObject (readonly)

Returns the value of attribute c_id.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def c_id
  @c_id
end

#component_typeObject (readonly)

Returns the value of attribute component_type.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def component_type
  @component_type
end

#groupedObject (readonly)

Returns the value of attribute grouped.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def grouped
  @grouped
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def node
  @node
end

#ntsoidObject (readonly)

Returns the value of attribute ntsoid.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def ntsoid
  @ntsoid
end

#statusesObject (readonly)

Returns the value of attribute statuses.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def statuses
  @statuses
end

#xnidObject (readonly)

Returns the value of attribute xnid.



4
5
6
# File 'lib/rsmp/component/component_base.rb', line 4

def xnid
  @xnid
end

Instance Method Details

#aggregated_status_changed(options = {}) ⇒ Object



99
100
101
# File 'lib/rsmp/component/component_base.rb', line 99

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

#clear_aggregated_statusObject



60
61
62
63
64
# File 'lib/rsmp/component/component_base.rb', line 60

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

#clear_alarm_timestampsObject



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

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

#get_alarm_state(alarm_code) ⇒ Object



56
57
58
# File 'lib/rsmp/component/component_base.rb', line 56

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

#inspectObject



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

def inspect
  "#<#{self.class.name}:#{object_id}:#{object_id} c_id:#{@c_id}>"
end

#log(str, options) ⇒ Object



66
67
68
69
# File 'lib/rsmp/component/component_base.rb', line 66

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

#nowObject



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

def now
  node.now
end

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

Raises:

  • (InvalidArgument)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rsmp/component/component_base.rb', line 71

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

#update_metadata(type: nil, name: nil) ⇒ Object



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

def (type: nil, name: nil)
  @component_type = type if type
  @name = name if name
end