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, #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) ⇒ ComponentProxy

Returns a new instance of ComponentProxy.



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

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

Instance Method Details

#allow_repeat_updates(subscribe_list) ⇒ Object

allow the next status update to be a repeat value



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

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.



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

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rsmp/component_proxy.rb', line 50

def handle_alarm message
#      code = message.attribute('aCId')
#      previous = @alarms[code]
#      if previous
#        unless message.differ?(previous)
#          raise RepeatedAlarmError.new("no changes from previous alarm #{previous.m_id_short}")
#        end
#        if Time.parse(message.attribute('aTs')) < Time.parse(previous.attribute('aTs'))
#          raise TimestampError.new("timestamp is earlier than previous alarm #{previous.m_id_short}")
#        end
#      end
#      p message
#    ensure
#      @alarms[code] = message
end

#store_status(message) ⇒ Object

Store the latest status update values



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

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