I am parsing XML data and trying to find specific entries for "alarms". I am successful for most of the data. However, it seems when parsing the notificationClass tag I cannot seem to pickup zero values. I have tried a few different things, including trying to cast to int, trying to see if maybe zero values come across as None types etc. Welcome to any ideas.
import xml.etree.cElementTree as et dd`
def niagaraXmlAlarm(deviceName,Ord,node):
alarmList=[{"Device,Name,Class,TimeDelay,NotificationClass,ToOffNormal,ToFault,ToNormal,NotifyType,AlarmText,HighLimit,LowLimit,deadband,LowEnabled,HighEnabled,ActiveText,InactiveText,AlarmEnabled"}]
foundAlm = False
nclass = node.get('class')
name = node.get('name')
activeText = ""
inActiveText = ""
almEnabled = ""
highLimit = ""
lowLimit = ""
db = ""
hiEnable = ""
lowEnable = ""
if nclass in alarmClasses:
timeDelay = node.findtext('properties/timeDelay/duration',"")
notificationClass = node.findtext('properties/notificationClass')
if isinstance(notificationClass,type(None)):
return
else:
notificationClass = int(notificationClass)
toOffNormal = node.findtext('properties/eventEnable/toOffnormal',"")
toFault = node.findtext('properties/eventEnable/toFault',"")
toNormal = node.findtext('properties/eventEnable/toNormal',"")
NotifyType = node.findtext('properties/notifyType',"")
txt = node.findtext('properties/alarmText',"")
if nclass == binaryAlmCls:
activeText = node.findtext('properties/activeInactiveText/active',"")
inActiveText = node.findtext('properties/activeInactiveText/inactive',"")
almEnabled = node.findtext('properties/alarmValueEnabled',"")
elif nclass == analogAlmCls:
highLimit = node.findtext('properties/highLimit',"")
lowLimit = node.findtext('properties/lowLimit',"")
db = node.findtext('properties/deadband',"")
hiEnable = node.findtext('properties/limitEnable/highLimitEnabled',"")
lowEnable = node.findtext('properties/limitEnable/lowLimitEnabled',"")
retVal = ",".join([deviceName,Ord,name,nclass,timeDelay,str(notificationClass),toOffNormal,toFault,toNormal,NotifyType,txt,highLimit,lowLimit,db,lowEnable,hiEnable,activeText,inActiveText,almEnabled])
return(retVal)
def recursifff(station,base,node):
if node.tag == 'node':
nodeBase = base+"/"+node.get('name')
print(nodeBase)
for x in node:
recursifff(station,nodeBase,x)
# print(node.tag,node.attrib)
row = niagaraXmlAlarm(station,nodeBase,node)
if not isinstance(row,type(None)):
alarms.append(row)
with open(tempFilePth,"r") as fd:
tree=et.parse(fd)
root = tree.getroot()
base =root[0].get('name')
#print(base)
for child in root[0]:
recursifff(singleName,base,child)
<node name="Alarms" class="tridium.containers.PollAlwaysContainer" module="coreRuntime" release="2.301.529.v1">
<node name="Room_Temp_Alarm_1" class="tridium.control.AnalogInputNode" module="coreRuntime" release="2.301.529.v1">
<properties>
<position><x>224</x><y>80</y></position>
<timeDelay>
<duration>300</duration>
</timeDelay>
<notificationClass>0</notificationClass>
<eventEnable>
<toOffnormal>true</toOffnormal>
<toFault>true</toFault>
<toNormal>false</toNormal>
</eventEnable>
<notifyType>alarm</notifyType>
<alarmText>Room 305 is Cold</alarmText>
<highLimit>90.0</highLimit>
<lowLimit>52.0</lowLimit>
<deadband>4.0</deadband>
<limitEnable>
<lowLimitEnabled>true</lowLimitEnabled>
<highLimitEnabled>false</highLimitEnabled>
</limitEnable>
</properties>
</node> <!-- Room_Temp_Alarm_1 -->