Colorado4Wheeler wrote:- Code: Select all
if old.onState == new.onState:
...
How I check for changes is iterate through all the attributes and states. So for states:
- Code: Select all
for key, val in old.states.iteritems():
if key in new.states and new.states[key] != old.states[key]:
....
Edit: I forgot to tack on .iteritems() to that iteration.
Thanks. I should've been more clear (told you I was code blind)...
I realize I can compare them element by element, I was hoping there was a more straightforward way of doing the comparison. I don't know, like with a dictionary comprehension or something:
- Code: Select all
dev1 = {'k1': 'v1', 'k2': 'v2'}
dev2 = {'k1': 'v1', 'k2': 'v3'}
d = {k: (dev1[k], dev2[k]) for k in dev1.keys() if dev1[k] != dev2[k]}
indigo.server.log(str(d))
Result:
- Code: Select all
{'k2': ('v2', 'v3')}
But that won't work for device objects. How about
indigo.listOfChanges(origDev, newDev)?
FlyingDiver wrote:And you're comparing the device object pointers, not the contents.
That's the bit I find perplexing. Why isn't it comparing the contents? If I compare two dictionaries with the same contents, they will come back as equal. In one case it's comparing the pointers and in the other case it's comparing the values.