This is probably basic, but it is killing me. I have read every post I could find on the subject. I want to go through Indigo devices to find the ones that have a state called "MAC" (e.g. Karl's Unifi plugin devices). My understanding is it is not a standard device state, and I need to use hasattr to see if a device uses this state prior to trying to read the state.
- Code: Select all
thisDevice = indigo.devices[1341466765]
testAttr = "MAC"
indigo.server.log(str(thisDevice.states)) #works, lists the device state info
indigo.server.log(str(thisDevice.states[testAttr])) #works,prints the MAC address
if hasattr(thisDevice.states, testAttr):
indigo.server.log("It has a MAC state.")
indigo.server.log(str(thisDevice.states[testAttr]))
else:
indigo.server.log("State not detected")
For whatever reason, I cannot figure out how to use hasattr to tell whether a device has the state or not. In this case, I am certain the device has a state named "MAC".
Thank you in advance!