Need help getting Child atomicState value in Parent


(Arn B) #1

In a child app the following atomicState is set as follows
atomicState.field = ‘12345678’

Then in the parent at a later time I want to get the atomicState.field value, it shows the atomicState object but when I try using it, a null error is thrown.
.
def childapps=findAllChildAppsByName(‘SHM Delay Child’)
childapps.each
{
log.debug "$it.simkeypad $it?.atomicState.field
// def obj=it?.atomicState.field
// obj.properties.each { k,v -> log.debug “$k $v”}
}

This
log.debug “$it.simkeypad $it?.atomicState.field”
generates this in live logging
pckeypad physicalgraph.app.InstalledSmartAppWrapper@6b34869?.atomicState.field
log.debug “$it.simkeypad ${it?.atomicState.field}”
generates an error
error java.lang.NullPointerException: Cannot get property ‘field’ on null object @line -1 (doCall)

Anyone know how to get the value of the child’s atomicState.field in a parent app?


(Arn B) #2

Solved this by adding a function in the child app that is called from the parent app

In childapp
def getAtomic(field_name)
{return atomicState[field_name]} //allow parent to get atomic data from child

In parent app
def simKeypadDevices=findAllChildAppsByName(‘SHM Delay Simkypd Child’)
SimKeypadDevices.each
{
log.debug “$it.simkeypad ${it.getAtomic(‘field’)}”
}


(www.rboyapps.com - Make your home your butler!) #3

Tagging @Jim here.

AFAIK that when a parent app calls a child device handler the return value cannot be relied upon as the ST design.

Jim does this hold true to parent/child apps also or can parent/child apps return values from methods reliably? If so is there is any restrictions on the return type?


(Arn B) #4

Thank you for the response.

The child app is a SmartApp, not a DTH, and it’s been reliably working as described in my earlier post. I have read about the restriction with atomicState in a DTH


(Jim Anderson) #5

I don’t know the answer. Maybe @gausnes knows?


(Luke - Backend Engineer) #6

@RBoy is right, when you call get childDevices or childApps it isn’t the SmartApp / Device Handler but instead a InstalledSmartApp / Device that has a subset of the functionality exposed.

See for documentation on what that object does support
http://docs.smartthings.com/en/latest/ref-docs/installed-smart-app-wrapper-ref.html


(Luke - Backend Engineer) #7

This topic was automatically closed after 28 hours. New replies are no longer allowed.