Using Built-In Virtual Devices as child devices

I have been thinking about many of my custom devices. I really should not need to recreate something as basic as a dimmer, or RGB light, or switch. I think it should be possible to add a built-in Virtual Switch as a child device to any of my custom devices. And then, to have a simple wrapper for the commands and events so that if parent != null then, call an associate parent function.

Example: Virtual Switch

capability "Switch"
capability "Actuator"
capability "Refresh"

on() {
    sendEvent(name: "switch", value: "on")
    if (parent) parent.childOn(this)
off() {
    sendEvent(name: "switch", value: "off")
    if (parent) parent.childOff(this)
refresh() {
    if (parent) parent.childRefresh(this)

I understand, refresh is not a capability for many virtual devices, but with these being used as possible child devices, it would make sense to make it possible. Plus, this is just an example. Doing something like this could eliminate a lot of custom child devices where the built-in devices could suffice.

@bravenel Do you think this is a possibility? Maybe there are limitation in the system I am not aware of, or not thinking through?

Why not just use the built-in component (child) drivers...

1 Like

What is that? I donā€™t see anything about that. Where can I learn more?

[update] ok, so knowing what to search for now I found they published the source to the generic component drivers and I do see them when searching. This will do. Seems to me the virtual drivers could have been auto-linked to the parent if one existed and not need the component driver, but this will work perfect! Thanks!