Alarms Models¶
Models responsible for storing alarm configurations and historical alarm data.
automation.dbmodels.alarms.AlarmTypes(*args, **kwargs)Database model for Alarm Types (e.g., HIGH, LOW, BOOL).
create(name)Creates a new Alarm Type if it doesn't exist.
Parameters:
- name (str): The name of the alarm type (e.g., 'HIGH').
Returns:
- dict: Result dictionary containing status message and data.
read_by_name(name)Retrieves an Alarm Type by name.
Parameters:
- name (str): Alarm type name.
Returns:
- AlarmTypes: The model instance or None.
name_exist(name)Checks if an Alarm Type name exists.
Parameters:
- name (str): Alarm type name.
Returns:
- bool: True if exists.
serialize(self)Serializes the record to a dictionary.
automation.dbmodels.alarms.AlarmStates(*args, **kwargs)Database model for Alarm States (ISA 18.2).
create(name, mnemonic, condition, status)Creates a new Alarm State.
Parameters:
- name (str): State name (e.g., 'Unacknowledged').
- mnemonic (str): Short code (e.g., 'UNACK').
- condition (str): Process condition.
- status (str): Status description.
Returns:
- AlarmStates: The created instance or existing one.
read_by_name(name)Retrieves an Alarm State by name.
name_exist(name)Checks if an Alarm State name exists.
serialize(self)Serializes the record.
automation.dbmodels.alarms.Alarms(*args, **kwargs)Database model for configured Alarms.
create(identifier, name, tag, trigger_type, trigger_value, description=None, state='Normal', timestamp=None)Creates a new Alarm configuration record.
Parameters:
- identifier (str): Unique ID.
- name (str): Alarm name.
- tag (str): Associated Tag name.
- trigger_type (str): Type of trigger.
- trigger_value (float): Threshold value.
- description (str, optional): Description.
- state (str, optional): Initial state.
- timestamp (datetime, optional): Creation timestamp.
Returns:
- Alarms: The created alarm record.
name_exists(name)Checks if an alarm name exists.
read(id)Reads an alarm by ID.
read_by_identifier(identifier)Reads an alarm by unique identifier.
read_by_name(name)Reads an alarm by name.
serialize(self)Serializes the alarm record.
automation.dbmodels.alarms.AlarmSummary(*args, **kwargs)Database model for Alarm History (Summary).
create(name, state, timestamp, ack_timestamp=None)Creates a new entry in the alarm summary.
Parameters:
- name (str): Alarm name.
- state (str): Alarm state.
- timestamp (datetime): Time of occurrence.
- ack_timestamp (datetime, optional): Acknowledgment time.
read_by_name(name)Retrieves the latest summary entry for a specific alarm name.
read_by_alarm_id(alarm_id)Retrieves the latest summary entry by alarm ID.
read_all(page=1, limit=20)Retrieves alarm summary records with pagination.
Parameters:
- page (int): Page number (default: 1).
- limit (int): Records per page (default: 20).
Returns:
- dict: {data: list, pagination: dict}
read_lasts(lasts=1)Retrieves the last N records.
filter_by(states=None, names=None, tags=None, greater_than_timestamp=None, less_than_timestamp=None, page=1, limit=20)Filters alarm summary records with pagination.
Parameters:
- states (list[str]): Filter by states.
- names (list[str]): Filter by alarm names.
- tags (list[str]): Filter by tag names.
- greater_than_timestamp (datetime): Start time in UTC (naive or timezone-aware).
- less_than_timestamp (datetime): End time in UTC (naive or timezone-aware).
- page, limit: Pagination control.
Returns:
- dict: {data: list, pagination: dict}
Note: All timestamps are expected to be in UTC. The model always works with UTC. Timezone conversions should be handled at the API endpoint level.
get_alarm_summary_comments(id)Retrieves comments associated with a specific alarm summary entry.
serialize(self)Serializes the summary record.