Class: RSMP::ComponentProxy

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

Overview

A proxy to a remote 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, #ntsOId, #statuses, #xNId

Instance Method Summary collapse

Methods inherited from ComponentBase

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

Methods included from Inspect

#inspect, #inspector

Constructor Details

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

Returns a new instance of ComponentProxy.



4
5
6
7
8
9
# File 'lib/rsmp/component_proxy.rb', line 4

def initialize node:, id:, grouped: false
  super
  @alarms = {}
  @statuses = {}
  @allow_repeat_updates = {}
end

Instance Method Details

#allow_repeat_updates(subscribe_list) ⇒ Object

allow the next status update to be a repeat value



12
13
14
15
16
17
18
19
# File 'lib/rsmp/component_proxy.rb', line 12

def allow_repeat_updates subscribe_list
  subscribe_list.each do |item|
    sCI = item['sCI']
    n = item['n']
    @allow_repeat_updates[sCI] ||= Set.new  # Set is like an array, but with no duplicates
    @allow_repeat_updates[sCI] << n
  end
end

#check_repeat_values(message, subscription_list) ⇒ Object

Check that were not receiving repeated update values. The check is not performed for item with an update interval.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rsmp/component_proxy.rb', line 23

def check_repeat_values message, subscription_list
  message.attribute('sS').each do |item|
    sCI, n, s, q = item['sCI'], item['n'], item['s'], item['q']
    uRt = subscription_list.dig(c_id,sCI,n,'uRt')
    next if uRt.to_i > 0
    next if @allow_repeat_updates[sCI] && @allow_repeat_updates[sCI].include?(n)
    new_values = {'s'=>s,'q'=>q}
    old_values = @statuses.dig(sCI,n)
    if new_values == old_values
      raise RSMP::RepeatedStatusError.new "no change for #{sCI} '#{n}'"
    end
  end
end

#handle_alarm(message) ⇒ Object

handle incoming alarm



49
50
51
52
53
# File 'lib/rsmp/component_proxy.rb', line 49

def handle_alarm message
  code = message.attribute('aCId')
  alarm = get_alarm_state code
  alarm.update_from_message message
end

#store_status(message) ⇒ Object

Store the latest status update values



37
38
39
40
41
42
43
44
45
46
# File 'lib/rsmp/component_proxy.rb', line 37

def store_status message
  message.attribute('sS').each do |item|
    sCI, n, s, q = item['sCI'], item['n'], item['s'], item['q']
    @statuses[sCI] ||= {}
    @statuses[sCI][n] = {'s'=>s,'q'=>q}

    # once a value is received, don't allow the value to be a repeat
    @allow_repeat_updates[sCI].delete(n) if @allow_repeat_updates[sCI]
  end
end