@JohnRob
Ok, so one more piece of information that will help you...
Inside a device driver, will will see createEvent (used inside parse() routine) and sendEvent() function calls. Whenever either of these is called, an 'Event' is created that allows other Apps to be woken up. If an App 'subscribes' to a particular device's particular events, that app will be made aware of that event and the specific routine within the App will be called.
So, in a perfect world... An App (let's use Rule Machine) decides that it is Sunset and needs to Turn On a Light. It does so by calling that particular device's 'on()' command. (Note: at this point, the device's 'switch' attribute is still 'off'.)
Inside that device's 'on()' command, the appropriate z-wave command is issued, thereby causing the z-wave radio to emit a signal to the real physical device.
The physical device receives the z-wave command to turn on the switch, it turns on a relay, and then sends a z-wave report back to the Hub. This message states that the 'switch' is now 'on'.
The Hub looks at the DeviceNetworkID of the z-wave packet it just received, and finds a corresponding device. Once it finds it, it passes the z-wave data to the parse() routine of that device.
The device's parse() routine picks apart the z-wave packet and determines that the switch is 'on'. It therefore performs a createEvent( name: switch, value: on) call. Doing so causes the device's internal 'switch' attribute to be changed from 'off' to 'on'.
Any Apps that are subscribed to this device's 'switch' attribute events, are then notified and have an internal function called with the data that the 'switch' is now 'on'. The App then takes any action that is appropriate.
Hopefully this helps.
As for Virtual Switches, they simply have a 'switch' attribute, and implement the 'on()' and 'off()' commands. When these commands run, they simply call 'sendEvent( name: switch, value: on)' or 'sendEvent( name: switch, value: off)' . Virtual devices typically do not have a parse() routine as there is no physical device to send them data.
Dan