PyAlarmEvent is basically just retrieving the entire list of properties, then checking if the string you provided matches the string name of a property. You could do this yourself; something like this (untested):
class WrappedAlarmEvent:
def __init__(self, basicEvent):
self.event = basicEvent
self.properties = {prop.name: event.getOrDefault(prop) for prop in event.properties}
def get(prop):
return self.properties.get(prop)
### Usage:
alarms = [WrappedAlarmEvent(alarm) for alarm in system.alarm.queryStatus()]
if alarms:
print alarms[0].get("associatedData")
It errors out saying prop is not defined. I think it’s the prop.name but not for sure. I changed it to for prop in event.properties not in the dictionary and print prop, it says 'java.beans.PropertyChangeEvent' object has no attribute 'properties'
class WrappedAlarmEvent:
def __init__(self, basicEvent):
self.event = basicEvent
self.properties = {prop.name: (event.getOrDefault(prop) for prop in event.properties)}
def get(prop):
return self.properties.get(prop)
if event.propertyName == "selectedAlarms":
alarmDatasetInfo = system.dataset.toPyDataSet(event.newValue)
if alarmDatasetInfo.getRowCount() >= 1:
for row in alarmDatasetInfo:
sourcePath = str(row["Source"])
alarms = [WrappedAlarmEvent(alarm) for alarm in system.alarm.queryStatus(source=[sourcePath])]
if alarms:
print alarms[0].get("keyPosition")
Excuse me, why there is no getEventTime() method about BasicAlarmEvent? I want to build my own AlarmStatusTable, but can’t get eventtime from AlarmEventObject.
The alarm event doesn’t directly keep track of the event time. Instead you get the EventData from whatever state the alarm is in:
And then EventData has a getTimestamp method that returns a long timestamp.
For anyone reading this in the future; in 8.1.11 we changed things around internally so every AlarmEvent you get in scripting will automatically be a PyAlarmEvent that does the wrapping here automatically.