Function of "parse" in Virtual Device Driver"

I'm wish to make a custom Virtual Device Driver to work with my DEW point calculation App

In the below example by BRavenel I can't figure out the purpose of the parse(description)
nor how the "def setOpenVentArea(area)" gets its data.

I suspect it's a "shortcut" where the parse output is implicitly available/sent to the "setOpenVentArea(area)" Method but cannot find and info to support this or help me understand its workings.

Any info would be appreciated.
John

metadata {
    definition (name: "Virtual Open Vent Area", namespace: "hubitat", author: "Bruce Ravenel") {
        capability "Sensor"
        command "setOpenVentArea", ["NUMBER"]
        attribute "openVentArea", "Number"

    }
    preferences {       // These become entries in the "device" page to ask us for our preferences!
        input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
    }
}

def installed() {
    log.warn "installed..."
    setOpenVentArea(0)
}

def updated() {
    log.info "updated..."
    log.warn "description logging is: ${txtEnable == true}"
}

def parse(String description) {
}

def setOpenVentArea(area) {
    def descriptionText = "${device.displayName} was set to $area"
    if (txtEnable) log.info "${descriptionText}"
    sendEvent(name: "openVentArea", value: area, unit: "sq. m", descriptionText: descriptionText)
}

Oversimplified:

Any message from a device is sent to Parse, where it's 'decoded' or... um parsed :slight_smile: The result is sent to the constituent methods.

In this case the parse is 'leave-the-message-alone' and just let it hit the method unaltered.

Indeed, virtuals don't get messages.

"When Events from Z-devices are passed into your Driver’s parse method, they are in an encoded string format. The first thing your parse method should do is call zigbee/zwave.parse on the description string to convert it to a Z-device command object."

Thanks but it leaves me at a loss...

In this case the parse is 'leave-the-message-alone' and just let it hit the method unaltered.
Indeed, virtuals don't get messages.

So in this case the parse receives a message (from somewhere) and does nothing with, no creating events, etc.

But the same unmodified text parse received pops up as "${descriptionText}" in another method. Is this kinda what you are saying?

Thanks
John

It's difficult to fathom from a Virtual, I think, because it's nothing to nothing...

Instead, consider a ZWave Driver... if i whittle it down to the minimum.. parse gets the 'raw' message. It might check for invalid, etc. but for legitimate messages, it sends it off to zwave.parse, as-is...

/*
	parse
    
	Respond to received zwave commands.
*/
def parse(String description) {
	def cmd = zwave.parse(description, [0x31: 5, 0x30: 1, 0x70: 1, 0x72: 1, 0x84: 1])
	if (cmd) { result = zwaveEvent(cmd) }
	return result
}

Which gets the 'result' back and then allows the Platform to call the 'handler'... of which are many overloaded:

def zwaveEvent(hubitat.zwave.Command cmd) {
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
def zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd) {
def zwaveEvent(hubitat.zwave.commands.configurationv1.ConfigurationReport cmd) {
def zwaveEvent(hubitat.zwave.commands.firmwareupdatemdv2.FirmwareMdReport cmd) {
def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv1.ManufacturerSpecificReport cmd) {
def zwaveEvent(hubitat.zwave.commands.notificationv3.NotificationReport cmd) {
def zwaveEvent(hubitat.zwave.commands.securityv1.NetworkKeyVerify cmd) {
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def zwaveEvent(hubitat.zwave.commands.sensorbinaryv1.SensorBinaryReport cmd) {
def zwaveEvent(hubitat.zwave.commands.sensormultilevelv5.SensorMultilevelReport cmd){
def zwaveEvent(hubitat.zwave.commands.versionv1.VersionCommandClassReport cmd) {

Drivers are basic tools to interpret.. and parse is the first step in that process.. and in this case, each zwaveEvent() is the last step... which itself may lead to more ZWave commands being sent.

Again, I'm not sure how helpful this massive simplification works for you, but this code is taken from the Aeotec MultiSensor 6 Driver.. if you want to see it without the simplification. :slight_smile:

Thank you for your time and explanation .....I'll have to chew on it a while.

John

Generally speaking for a virtual device driver there is no need for a parse() method. However, there is one important exception: It is possible to route LAN messages to a virtual device's parse method. This is done for example with Hub Link app, and you can see an example of how that's done here:

So, as a general rule, one puts a parse() method in a virtual device driver, and does with it whatever would make sense were it called with some value in the message to it.

Thankyou, that makes sense, however I'm still stuck as to why in your vent example (included in my post #1) is the parse Method even included?

And what is the setOpenVent(area) method doing? From the little I've learned there is not way for the setOpenVent method to run.

John

The setOpenVentArea is a command for that driver. An app can call it with

myVent.setOpenVentArea(myArea)

Doing so causes the event to be sent, and that in turn sets the attribute called openVentArea.

1 Like

Thank you so much. I'm too green at this to remember this capability of a driver :slight_smile:

This is the basic way you create "custom" drivers, with custom attributes and custom commands. sendEvent is the means inside the command method to set the attribute, as this driver illustrates.

My suggestion: try it for yourself.

1 Like

I will :slight_smile:

BTW The driver I was thinking of is the HomeSeer HD-200+ which exposed the control front panel LED method to the outside world.
John