Class: RSMP::Component

Inherits:
ComponentBase show all
Defined in:
lib/rsmp/component.rb

Overview

RSMP component

Constant Summary

Constants inherited from ComponentBase

RSMP::ComponentBase::AGGREGATED_STATUS_KEYS

Instance Attribute Summary

Attributes inherited from ComponentBase

#aggregated_status, #aggregated_status_bools, #alarms, #c_id, #grouped, #node, #statuses

Instance Method Summary collapse

Methods inherited from ComponentBase

#aggregated_status_changed, #clear_aggregated_status, #log, #set_aggregated_status, #set_aggregated_status_bools

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:, grouped: false) ⇒ Component

Returns a new instance of Component.



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

def initialize node:, id:, grouped: false
  super
end

Instance Method Details

#activate_alarm(alarm_code) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rsmp/component.rb', line 38

def activate_alarm alarm_code
  alarm = get_alarm_state alarm_code
  return if alarm.active
  log "Activating alarm #{alarm_code}", level: :info
  alarm.activate
  @node.alarm_changed alarm
end

#deactivate_alarm(alarm_code) ⇒ Object



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

def deactivate_alarm alarm_code
  alarm = get_alarm_state alarm_code
  return unless alarm.active
  log "Deactivating alarm #{alarm_code}", level: :info
  alarm.deactivate
  @node.alarm_changed alarm
end

#get_alarm_state(alarm_code) ⇒ Object



18
19
20
# File 'lib/rsmp/component.rb', line 18

def get_alarm_state alarm_code
  alarm = @alarms[alarm_code] ||= RSMP::AlarmState.new component_id: c_id, code: alarm_code
end

#get_status(status_code, status_name = nil) ⇒ Object



14
15
16
# File 'lib/rsmp/component.rb', line 14

def get_status status_code, status_name=nil
  raise UnknownStatus.new "Status #{status_code}/#{status_name} not implemented by #{self.class}"
end

#handle_command(command_code, arg) ⇒ Object



10
11
12
# File 'lib/rsmp/component.rb', line 10

def handle_command command_code, arg
  raise UnknownCommand.new "Command #{command_code} not implemented by #{self.class}"
end

#resume_alarm(alarm_code) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rsmp/component.rb', line 30

def resume_alarm alarm_code
  alarm = get_alarm_state alarm_code
  return unless alarm.suspended
  log "Resuming alarm #{alarm_code}", level: :info
  alarm.resume
  @node.alarm_changed alarm
end

#suspend_alarm(alarm_code) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rsmp/component.rb', line 22

def suspend_alarm alarm_code
  alarm = get_alarm_state alarm_code
  return if alarm.suspended
  log "Suspending alarm #{alarm_code}", level: :info
  alarm.suspend
  @node.alarm_changed alarm
end