Parent-Child App with Devices?

I’m going a little crazy over here and I can’t even figure out if this should work. I’m attempting to write a Google Calendar app that creates Contact Sensors based on calendar/search. Kind of merging the Service Manager and Parent-Child app into one.

So I have the parent app

  • GCal Search

That creates instances of the child app

  • GCal Search Trigger

In the trigger I create the custom device type

  • GCal Event

So far things are going well. When I’m on the device tile for the GCal Event I want to have a refresh button to pull the latest event that matches. So I call parent.getNextEvent() which I thought was going to call GCal Seach Trigger.getNextEvent()

Instead it passes over that call never calling any of my log/trace statements in child app.

Is this even possible or does the device never know who it’s parent is? It does error out if I give it an invalid method to call on the parent so it makes me think it’s possible.

I’ve even gone down the path of creating an event and subscribing to it in order to get this working. I still don’t get any of my log/trace calls in the live log but it is showing as subscribed in the app.

Is there a code cache somewhere I have to invalidate?

you’re calling parent.NextEvent() from the device type?, the parent notation is for the child app to execute methods defined in the parent.
device to smart app communication is via device subscriptions
smart app to device communication is via myDevice.goAndDoSomething()

1 Like

You can use parent.method() in a devicetype that calls to the parent SmartApp that created it as a child device. This is used in Service Manager SmartApps like Hue Connect. I’ve used this practice in a couple of custom SmartApps.

@mnestor, are you sure the refresh button is calling a command in the child devicetype? Do you have a log statement there to confirm?

I learn something every day…

I do. I log that I call, grab the return from the parent call and log that but it’s null. Never get a log from the parent method.

Having some git issues but will post the code when I fix that.

Trigger Child App:

def getDeviceID() {
log.debug “we got called to get the device ID!”
return “GCal_${app.id}”
}

def getNextEvents() {
log.debug “getNextEvents() trigger”
def search = settings.search

return events

Device Handler

def update() {
log.trace “update()”
poll()
}

def poll() {
log.trace “poll()”
def events = parent.getNextEvents()
log.debug “events: ${ev}”

Log…
4:59:04 PM: debug events: null
4:59:04 PM: trace poll()
4:59:04 PM: trace update()

Perhaps I need more capability than just Contact Sensor?

Okay, I’ve found that none of my log statements work in the Child App when called from the Device but the code is still being executed. Ugh! How to debug this crap then?!?!

I think I’ve just wasted the last hour due to this bug too!!

+1 Ughs!!

Although I think you mean “log statements in a parent (Service Manager SmartApp) do not work when a command is called from a child device, even though though the rest of the code is still being executed”.

SmartThings Devs, please fix this, it’s a nightmare to debug child-parent interaction, or at least explain why it is so…