Not sure why, but after many years, I'm still unsure how plugins with children are meant to be coded, although I've got away with doing a few with no problems!
I could try out a few test cases but messing around with luup.chdev.append() is tricky. If the appended info changes, a luup.engine restart occurs. Any stuff ups and this can go into a continuous loop. Plus I don't want random new devices scattered all over my installation.
So imagine a plugin that controls say ten binary lights, ten dimmers and ten blinds/shutters:
the plugin should have in the device file D_xyx.xml the tag:
<handleChildren>1</handleChildren>
OK it makes sense for the parent to have the routines to control the child devices.
Question: when wouldn't the plugin parent not have the code to control its children? ie
<handleChildren>0</handleChildren>
Seems redundant or I have misunderstood something?
The service files for both dimmers and blinds have the function:
<action>
<name>SetLoadLevelTarget</name>
<argumentList>
<argument>
<name>newLoadlevelTarget</name>
<direction>in</direction>
<relatedStateVariable>LoadLevelTarget</relatedStateVariable>
</argument>
</argumentList>
</action>
And to call the action in each case, we have say 'dimmingLevel' vs 'blindPosition':
luup.call_action('urn:upnp-org:serviceId:Dimming1', "SetLoadLevelTarget", {newLoadlevelTarget = dimmingLevel}, deviceId)
luup.call_action('urn:upnp-org:serviceId:Dimming1', "SetLoadLevelTarget", {newLoadlevelTarget = blindPosition}, deviceId)
Question: how do you direct the same calls to different functions in the plugin - one to dim the light and the other to postion the blind? It would seem that you would have to look at the target child device and see what type it is, then act accordingly? An example would be good!
In this plugin, devices can come and go - not often - but still needs to be attended to in the code. So the luup.chdev.append() call is executed at every start up. Each child has a descriptive name. When the child is first created this name can be set up by the software to say "Light 1" to "light 10". The user can then subsequently change this descriptive name.
Question: How do I know that this descriptive name has been changed by the user and needs to be preserved and how do I check what this descriptive name is ready for when the luup.chdev.append() call is executed? As the function needs this descriptive name.
And I wonder how openluup (without looking at the code) emulates the C blob:
local childDevices = luup.chdev.start(THIS_LUL_DEVICE)