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:
The Alarm Manager |
- class pvp.alarm.alarm_manager.Alarm_Manager[source]¶
The Alarm Manager
The alarm manager receives
SensorValues
from the GUI viaAlarm_Manager.update()
and emitsAlarm
s to methods given byAlarm_Manager.add_callback()
. When alarm limits are updated (ie. theAlarm_Rule
hasdepends
), it emits them to methods registered withAlarm_Manager.add_dependency_callback()
.On initialization, the alarm manager calls
Alarm_Manager.load_rules()
, which loads all rules defined inalarm.ALARM_RULES
.- cleared_alarms¶
of
AlarmType
s, alarms that have been cleared but have not dropped back into the ‘off’ range to enable re-raising- Type
- snoozed_alarms¶
of
AlarmType
s : times, alarms that should not be raised because they have been silenced for a period of time- Type
- depends_callbacks¶
When we
update_dependencies()
, we send back aControlSetting
with the new min/max- Type
- rules¶
A dict mapping
AlarmType
toAlarm_Rule
.- Type
If an Alarm_Manager already exists, when initing just return that one
Attributes:
Methods:
Copy alarms from
alarm.ALARM_RULES
and callAlarm_Manager.load_rule()
for eachload_rule
(alarm_rule)Add the Alarm Rule to
Alarm_Manager.rules
and register any dependencies they have withAlarm_Manager.register_dependency()
update
(sensor_values)Call
Alarm_Manager.check_rule()
for all rules inAlarm_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
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 callAlarm_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 withAlarm_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 inAlarm_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 withAlarmSeverity.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 checksensor_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
alarm_type (
AlarmType
) –severity (
AlarmSeverity
) –
- 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
- 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
- get_alarm_severity(alarm_type: pvp.alarm.AlarmType)[source]¶
Get the severity of an Alarm
- Parameters
alarm_type (
AlarmType
) – Alarm type to check- Returns
- 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.
- 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.