Setting parent state variables from child DeviceType


(Chuck Pearce) #1

Okay, this is pretty deep into the abilities of the SDK.

I am attempting to update the variable state.pausedOn in the function pauseSchedule in the following:

SmartApp: https://github.com/chuckpearce/stRepo/blob/master/gist/rain8net.js
DeviceType: https://github.com/chuckpearce/stRepo/blob/master/gist/sprinklerZone.js

(Please don’t judge that code, it is riddled with debugging information and “hacks” for prior to using my webservice call of debugging.)

However, what is happening is no state variables are being persisted. The variable is persisted within the pauseSchedule function, but after scheduling the resumePausedSchedule function the state variables are all reset to what they were prior.

I have confirmed that initialize() is not being run multiple times. So, my big question is, is this an intended behavior, a bug, or just an unintended consequences of the architecture?

If state variables can not persist between child/parent, is there a reasonable method of passing these variables in a way that they will persist?

EDIT

Server Log: https://github.com/chuckpearce/stRepo/blob/master/gist/server.log
SmartApp Log: https://github.com/chuckpearce/stRepo/blob/master/gist/smartapp.log


(Mike Maxwell) #2

My understanding is that calls made using parent.someMethod() are run in a different thread, so if this method on the app side is setting your state var, then maybe it’s out of scope and not actually being set?

You can also send data to a smart app thus:
return sendEvent(name: “switch”, value: “on”, data: “~${action}~”)
Then in the smart app:
def cmd = evt.data.split("~")[1]


(Chuck Pearce) #3

Ahhh thank you I forgot you could emit events back to the parent app. I will give that a shot!

And yes I agree with your understanding that they are within a different scope/thread which would facilitate instancing on their cloud.