Simulate button click on child devices

I have custom app code that create child devices from api call information. So, it populate availlable properties on the login but to update some other, the child device must click a button, so the driver call function inside the app. I would like to update those properties directly without clicking a button, each time the app get refreshed.
in app:
updatestatus(com.hubitat.app.DeviceWrapper device, Boolean refresh = false, Boolean retry=false)
in driver:

void refresh()
{
    log("refresh called", "trace")
    parent.updatestatus(device, fullRefresh, false)
    updateHtml()
}

So, how can I get all child devices and run this module for each one? (device) is the child Id I think.
Thanks!

1 Like

parent?.componentInitialize(this.device)

"componentInitialize" would exist in the parent and then push the items to the calling child:

// called by each child when it wants an update of these values.
def componentInitialize(cd) { 
		cd.set2DayGroup(state.dayGroup) 
		cd.setOutdoorTemp(outdoorTempDevice, maxOutdoorTemp) 
}

Obviously, "cd" is the child device and the modules must exist within the child.

def setOutdoorTemp(k,dTemp) {
	state.outdoorTempDevice = k
	state.maxOutdoorTemp = dTemp
	logInfo "OutdoorTemp update from Parent." /// $k, $dTemp"
}

In other words, the parent can, for whatever reason, pass items to the child:

	childApps.each {child ->
		child.set2DayGroup(state.dayGroup) 
		child.setOutdoorTemp(outdoorTempDevice, maxOutdoorTemp) 
	}

AND, the child can ask the parent to send them, child-by-child

2 Likes

I m new to this so not sure to understand, here the complete thing. I get car properties on a website and then get other status with another api call. So, the car become the child device created. My app code is this:

void authorize() {
 I make api call here to login  
getcar()
}
void updateStatus(com.hubitat.app.DeviceWrapper device, Boolean refresh = false, Boolean retry=false)
{
new api call for other properties
}

then, the driver :

void refresh()
{
    log("refresh called", "trace")
    parent.updateStatus(device, fullRefresh, false)
    updateHtml()
}

So, I would like to run the updatestatus in the app for each child devices. I tried your code but not sure I used it the right way. Hope this would help you to help me! :slight_smile:
Thanks!

I'm not sure it's clearer :smiley:

You can only push objects from parent to child or from child to parent.

If you have an object, big or small, on one side, you can push it to the other.

In my example above, I have two objects that are known to the parent: outdoorTempDevice, maxOutdoorTemp One is a device object, the other is a value. That code sends them to the child. The child receives them and processes them. And of course you don't have to pass anything :smiley: The parent can tell the child to go do something, and the something is in the code that gets invoked in the child.

The opposite is entirely true as well. The child can acquire data that needs to be transferred to the parent OR as in the example above, the child asks the parent to send something.

Your code seems to be the Child sending to the Parent. You have (device, fullRefresh, false) known to the child and it's passing the objects to the parent. The parent gets them in updateStatus.

Yes, actually, your last words is excatly what it does but I need to click a button to trigger the child that trigger the parent and the parent call the api to refresh...

What I want to do is force all childs to 'click' their button to force them to refresh but from the parent.

now, in the parent, I call the autorize() part that login and get token, from there I call the getvehicles() that makes an api call to get all registrated car. After that, for each car, I call the driver to create the child with primary informations.
From inside the child I can trigger the refresh but I would like to trigger it from the app so the child would be updated without to press that button...

I tough I could use getchilddevices() but not sure how to use it...

here the link to the app I started with, the driver should be in the repo, I think it ll help to understand better what it is!

thanks!

I got it by using :

for (device in getChildDevices())
    {
mymodule(device)
}

Thanks