Class: RSMP::ComponentProxy
- Inherits:
-
ComponentBase
- Object
- ComponentBase
- RSMP::ComponentProxy
- Defined in:
- lib/rsmp/component/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
-
#allow_repeat_updates(subscribe_list) ⇒ Object
allow the next status update to be a repeat value.
-
#check_repeat_values(message, subscription_list) ⇒ Object
Check that were not receiving repeated update values.
- #check_status_item_for_repeats(item, subscription_list) ⇒ Object
-
#handle_alarm(message) ⇒ Object
handle incoming alarm.
-
#initialize(node:, id:, ntsoid: nil, xnid: nil, grouped: false) ⇒ ComponentProxy
constructor
A new instance of ComponentProxy.
- #should_check_repeats?(subscription_list, status_code, status_name) ⇒ Boolean
-
#store_status(message) ⇒ Object
Store the latest status update values.
- #update_rate_set?(subscription_list, status_code, status_name) ⇒ Boolean
Methods inherited from ComponentBase
#aggregated_status_changed, #clear_aggregated_status, #clear_alarm_timestamps, #get_alarm_state, #log, #now, #set_aggregated_status
Methods included from Inspect
Constructor Details
#initialize(node:, id:, ntsoid: nil, xnid: nil, grouped: false) ⇒ ComponentProxy
Returns a new instance of ComponentProxy.
4 5 6 7 8 9 |
# File 'lib/rsmp/component/component_proxy.rb', line 4 def initialize(node:, id:, ntsoid: nil, xnid: nil, 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/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 |
# File 'lib/rsmp/component/component_proxy.rb', line 23 def check_repeat_values(, subscription_list) .attribute('sS').each do |item| check_status_item_for_repeats(item, subscription_list) end end |
#check_status_item_for_repeats(item, subscription_list) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rsmp/component/component_proxy.rb', line 29 def check_status_item_for_repeats(item, subscription_list) status_code = item['sCI'] status_name = item['n'] return if update_rate_set?(subscription_list, status_code, status_name) return unless should_check_repeats?(subscription_list, status_code, status_name) new_values = { 's' => item['s'], 'q' => item['q'] } old_values = @statuses.dig(status_code, status_name) raise RSMP::RepeatedStatusError, "no change for #{status_code} '#{status_name}'" if new_values == old_values end |
#handle_alarm(message) ⇒ Object
handle incoming alarm
69 70 71 72 73 |
# File 'lib/rsmp/component/component_proxy.rb', line 69 def handle_alarm() code = .attribute('aCId') alarm = get_alarm_state code alarm. end |
#should_check_repeats?(subscription_list, status_code, status_name) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/rsmp/component/component_proxy.rb', line 45 def should_check_repeats?(subscription_list, status_code, status_name) soc = subscription_list.dig(c_id, status_code, status_name, 'sOc') return false if soc == false return false if @allow_repeat_updates[status_code]&.include?(status_name) true end |
#store_status(message) ⇒ Object
Store the latest status update values
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rsmp/component/component_proxy.rb', line 54 def store_status() .attribute('sS').each do |item| sci = item['sCI'] n = item['n'] s = item['s'] q = 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) end end |
#update_rate_set?(subscription_list, status_code, status_name) ⇒ Boolean
40 41 42 43 |
# File 'lib/rsmp/component/component_proxy.rb', line 40 def update_rate_set?(subscription_list, status_code, status_name) urt = subscription_list.dig(c_id, status_code, status_name, 'uRt') urt.to_i.positive? end |