Alarm Manager

The alarm manager is responsible for checking the Alarm_Rule s and maintaining the Alarm s active in the system.

Only one instance of the Alarm_Manager can be created at once, and if it is instantiated again, the existing object will be returned.

Classes:

Alarm_Manager()

The Alarm Manager

class pvp.alarm.alarm_manager.Alarm_Manager[source]

The Alarm Manager

The alarm manager receives SensorValues from the GUI via Alarm_Manager.update() and emits Alarm s to methods given by Alarm_Manager.add_callback() . When alarm limits are updated (ie. the Alarm_Rule has depends ), it emits them to methods registered with Alarm_Manager.add_dependency_callback() .

On initialization, the alarm manager calls Alarm_Manager.load_rules() , which loads all rules defined in alarm.ALARM_RULES .

active_alarms

{AlarmType: Alarm}

Type

dict

logged_alarms

A list of deactivated alarms.

Type

list

dependencies

A dictionary mapping ValueName s to the alarm threshold dependencies they update

Type

dict

pending_clears

[AlarmType] list of alarms that have been requested to be cleared

Type

list

callbacks

list of callables that accept Alarm s when they are raised/altered.

Type

list

cleared_alarms

of AlarmType s, alarms that have been cleared but have not dropped back into the ‘off’ range to enable re-raising

Type

list

snoozed_alarms

of AlarmType s : times, alarms that should not be raised because they have been silenced for a period of time

Type

dict

callbacks

list of callables to send Alarm objects to

Type

list

depends_callbacks

When we update_dependencies(), we send back a ControlSetting with the new min/max

Type

list

rules

A dict mapping AlarmType to Alarm_Rule .

Type

dict

If an Alarm_Manager already exists, when initing just return that one

Attributes:

_instance

active_alarms

logged_alarms

dependencies

pending_clears

cleared_alarms

snoozed_alarms

callbacks

depends_callbacks

rules

logger

Methods:

load_rules()

Copy alarms from alarm.ALARM_RULES and call Alarm_Manager.load_rule() for each

load_rule(alarm_rule)

Add the Alarm Rule to Alarm_Manager.rules and register any dependencies they have with Alarm_Manager.register_dependency()

update(sensor_values)

Call Alarm_Manager.check_rule() for all rules in Alarm_Manager.rules

check_rule(rule, sensor_values)

check() the alarm rule, handle logic of raising, emitting, or lowering an alarm.

emit_alarm(alarm_type, severity)

Emit alarm (by calling all callbacks with it).

deactivate_alarm(alarm)

Mark an alarm's internal active flags and remove from active_alarms

dismiss_alarm(alarm_type[, duration])

GUI or other object requests an alarm to be dismissed & deactivated

get_alarm_severity(alarm_type)

Get the severity of an Alarm

register_alarm(alarm)

Be given an already created alarm and emit to callbacks.

register_dependency(condition, dependency, ...)

Add dependency in a Condition object to be updated when values are changed

update_dependencies(control_setting)

Update Condition objects that update their value according to some control parameter

add_callback(callback)

Assert we're being given a callable and add it to our list of callbacks.

add_dependency_callback(callback)

Assert we're being given a callable and add it to our list of dependency_callbacks

clear_all_alarms()

call Alarm_Manager.deactivate_alarm() for all active alarms.

reset()

Reset all conditions, callbacks, and other stateful attributes and clear alarms

_instance = None
active_alarms: Dict[pvp.alarm.AlarmType, pvp.alarm.alarm.Alarm] = {}
logged_alarms: List[pvp.alarm.alarm.Alarm] = []
dependencies = {}
pending_clears = []
cleared_alarms = []
snoozed_alarms = {}
callbacks = []
depends_callbacks = []
rules = {}
logger = <Logger pvp.alarm.alarm_manager (WARNING)>
load_rules()[source]

Copy alarms from alarm.ALARM_RULES and call Alarm_Manager.load_rule() for each

load_rule(alarm_rule: pvp.alarm.rule.Alarm_Rule)[source]

Add the Alarm Rule to Alarm_Manager.rules and register any dependencies they have with Alarm_Manager.register_dependency()

Parameters

alarm_rule (Alarm_Rule) – Alarm rule to be loaded

update(sensor_values: pvp.common.message.SensorValues)[source]

Call Alarm_Manager.check_rule() for all rules in Alarm_Manager.rules

Parameters

sensor_values (SensorValues) – New sensor values from the GUI

check_rule(rule: pvp.alarm.rule.Alarm_Rule, sensor_values: pvp.common.message.SensorValues)[source]

check() the alarm rule, handle logic of raising, emitting, or lowering an alarm.

When alarms are dismissed, an alarm.Alarm is emitted with AlarmSeverity.OFF .

  • If the alarm severity has increased, emit a new alarm.

  • If the alarm severity has decreased and the alarm is not latched, emit a new alarm

  • If the alarm severity has decreased and the alarm is latched, check if the alarm has been manually dismissed, if it has emit a new alarm.

  • If a latched alarm has been manually dismissed previously and the alarm condition is now no longer met, dismiss the alarm.

Parameters
  • rule (Alarm_Rule) – Alarm rule to check

  • sensor_values (SensorValues) – sent by the GUI to check against alarm rule

emit_alarm(alarm_type: pvp.alarm.AlarmType, severity: pvp.alarm.AlarmSeverity)[source]

Emit alarm (by calling all callbacks with it).

Note

This method emits and clears alarms – a cleared alarm is emitted with AlarmSeverity.OFF

Parameters
deactivate_alarm(alarm: (<enum 'AlarmType'>, <class 'pvp.alarm.alarm.Alarm'>))[source]

Mark an alarm’s internal active flags and remove from active_alarms

Typically called internally when an alarm is being replaced by one of the same type but a different severity.

Note

This does not alert listeners that an alarm has been cleared, for that emit an alarm with AlarmSeverity.OFF

Parameters

alarm (AlarmType , Alarm) – Alarm to deactivate

dismiss_alarm(alarm_type: pvp.alarm.AlarmType, duration: Optional[float] = None)[source]

GUI or other object requests an alarm to be dismissed & deactivated

GUI will wait until it receives an emit_alarm of severity == OFF to remove alarm widgets. If the alarm is not latched

If the alarm is latched, alarm_manager will not decrement alarm severity or emit OFF until a) the condition returns to OFF, and b) the user dismisses the alarm

Parameters
  • alarm_type (AlarmType) – Alarm to dismiss

  • duration (float) – seconds - amount of time to wait before alarm can be re-raised If a duration is provided, the alarm will not be able to be re-raised

get_alarm_severity(alarm_type: pvp.alarm.AlarmType)[source]

Get the severity of an Alarm

Parameters

alarm_type (AlarmType) – Alarm type to check

Returns

AlarmSeverity

register_alarm(alarm: pvp.alarm.alarm.Alarm)[source]

Be given an already created alarm and emit to callbacks.

Mostly used during testing for programmatically created alarms. Creating alarms outside of the Alarm_Manager is generally discouraged.

Parameters

alarm (Alarm) –

register_dependency(condition: pvp.alarm.condition.Condition, dependency: dict, severity: pvp.alarm.AlarmSeverity)[source]

Add dependency in a Condition object to be updated when values are changed

Parameters
  • condition (dict) – Condition as defined in an Alarm_Rule

  • dependency (dict) – either a (ValueName, attribute_name) or optionally also + transformation callable

  • severity (AlarmSeverity) – severity of dependency

update_dependencies(control_setting: pvp.common.message.ControlSetting)[source]

Update Condition objects that update their value according to some control parameter

Call any transform functions on the attribute of the control setting specified in the depencency.

Emit another ControlSetting describing the new max or min or the value.

Parameters

control_setting (ControlSetting) – Control setting that was changed

add_callback(callback: Callable)[source]

Assert we’re being given a callable and add it to our list of callbacks.

Parameters

callback (Callable) – Callback that accepts a single argument of an Alarm

add_dependency_callback(callback: Callable)[source]

Assert we’re being given a callable and add it to our list of dependency_callbacks

Parameters

callback (Callable) – Callback that accepts a ControlSetting

Returns:

clear_all_alarms()[source]

call Alarm_Manager.deactivate_alarm() for all active alarms.

reset()[source]

Reset all conditions, callbacks, and other stateful attributes and clear alarms