Enum values e.g. for DataQuality

This might be an obvious question to some, but my java knowledge is lacking…

(excuse the horrible terminology) In Python scripting, how can I compare a value that is returned as an enum, to a value within the enum ‘variable’ (class?).

E.g.
qual = system.tag.read(‘tagpath’).quality returns a DataQuality enum member, for example NOT_FOUND.
how can I compare this enum value to one of the members in the enum?
E.g. qual == DataQuality.NOT_FOUND

Cheers!

The easiest way is to import the class from Java:

#import DataQuality
from com.inductiveautomation.ignition.common.sqltags.model.types import DataQuality

#use DataQuality
qual = system.tag.read("bogus").quality
if qual == DataQuality.NOT_FOUND:
  print "not found"
else:
  print "found, qual is", qual
1 Like

And to anticipate your next question, which is “how on earth would I know what package to import DataQuality from?”, you’d go to the SDK Javadocs for DataQuality:
http://files.inductiveautomation.com/sdk/javadoc/ignition79/790-beta1/com/inductiveautomation/ignition/common/sqltags/model/types/DataQuality.html . :grinning:

1 Like

I don’t know if theres a specific reason you want to compare to the enum, but if you’re just looking to see if a tag is Good, Not Found, Disabled, etc - you can wrap str() around the .quality value and it’ll give you a string with the quality.

An example using most of Kathy’s example code:

qual = system.tag.read("bogus").quality
if str(qual) == "Not Found":
  print "not found"
else:
  print "found, qual is", qual
1 Like

Thanks Kathy! I’ve been beating against this all afternoon! And thanks for the anticipation of my next question, though I’'m still enough of a novice that it’d be a long while before I thought to go there!
As to mrogers comment - I never would have thought of using “str” - I did spend a considerable amount of time trying to coerce the freaking thing into an int (specifically I was looking for any 410’s - DISABLED) since the manual insists that quality is an integer and proceeds to give the whole list of corresponding numerical values.
Seriously, if you’re going to go to the trouble of making that nice comprehensive chart in the manual (https://docs.inductiveautomation.com/display/DOC79/Tag+Quality+and+Overlays) , you REALLY ought to mention that it isn’t of any use without the DataQuality enumeration!

The int value is used a lot of places in Ignition. For example, if you use system.gui.getQuality, you’ll get the int value from the nice comprehensive chart in the manual. Then you’ll have your choice of writing code like

if qualityCode != 192:```

or 

```qualityCode = system.gui.getQuality(event.source.parent.getComponent('Numeric Label'), "value")
if qualityCode != DataQuality.GOOD_DATA.getIntValue()```

The first way is more compact, the second way is easier to grok the meaning of six months later. Your choice. :slight_smile:

Thanks for the clarification. However, in my case, the script in question doesn’t have any specific components to reference as it is a rather “headless” script used as a template. But I used your enum with much satisfaction…

    tagAttribs = system.tag.read(tagPath)
  tagQual = tagAttribs.quality
  Dissed = DataQuality.getQualityFor(410)
  if tagQual == Dissed: 
  	system.tag.write("thisTagEnabled",False)
  else:
  	system.tag.write("thisTagEnabled",True)

Thank you!