David Sanner - Can a notification state get up...
Can a notification state get updated before its associated path value is updated?
Seems backwards but when I get a notification for a path entering a zone and I print that path's value via app.getSelfPath(somePath.value) it hasn't been updated.
So notification.somePATH.state can change before somePath.value has been updated to the value for the corresponding zone/notification.
Seems backwards but when I get a notification for a path entering a zone and I print that path's value via app.getSelfPath(somePath.value) it hasn't been updated.
So notification.somePATH.state can change before somePath.value has been updated to the value for the corresponding zone/notification.
7 Replies
In a plugin?
Yes, the plugin is subscribed to notifications.* / instant and when processing a notification event I check the corresponding value via app.getSelfPath and it doesn't seem to have been updated yet.
A little more testing: in my function that handles notifications that have been subscribed to, if I wrap getSelfPath like this:
setTimeout(function() {val = app.getSelfPath(somePath).value }, 0)
I get the proper value (the one that is in the zone that triggered notification.somePath). Otherwise I get the value before the path entered the zone.
eg. "path": "electrical.batteries.bmv.relay" When I enable the relay the associated zone triggers a notification but when I check the value via app.getSelfPath(selectrical.batteries.bmv.relay).value I get 0 (unless I wrap the call as shown above) I guess since setTimeout is asynchronous it's allowing other sk server code to execute ... so that the path value gets updated??
eg. "path": "electrical.batteries.bmv.relay" When I enable the relay the associated zone triggers a notification but when I check the value via app.getSelfPath(selectrical.batteries.bmv.relay).value I get 0 (unless I wrap the call as shown above) I guess since setTimeout is asynchronous it's allowing other sk server code to execute ... so that the path value gets updated??
Exactly. Was going to suggest nexttick in your code to allow the value to be updated
But i think we should fix the zones processing, so that the new value is there when the notification is sent
Node.js — Understanding process.nextTick()
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Nice... just coded w/ nextTick which does the same async trick but it does make sense the the value triggering a notification would get updated first. Thx, good to know I wasn't "seeing things"
Want to create an issue lest we forget the proper fix?