Is && not allowed for comparing multiple parameters in the same cmd.output?

devicetype

(Robert Vandervoort) #1

This was really hurt my brain and I settled on a less elegant || which was ok but only luckily since none of the specific events shared the particular parameter value. Check this out… I had,

def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd) { if (state.debug) log.debug "---NOTIFICATION REPORT V3--- ${device.displayName} sent eventParameter: ${cmd.eventParameter} notificationType: ${cmd.notificationType} event: ${cmd.event}" def result = [] // for the cover removal if (cmd.eventParameter == 3 && cmd.notificationType == 7) { switch (cmd.event) { case 0: result << createEvent(name: "acceleration", value: "inactive", descriptionText: "The cover was replaced on $device.displayName", isStateChange: true) motionEvent(0) break case 3: result << createEvent(name: "acceleration", value: "active", descriptionText: "The cover was removed from $device.displayName", isStateChange: true) break } } // now for motion else if (cmd.eventParameter == 8 && cmd.notificationType == 7) { switch (cmd.event) { case 0: motionEvent(0) break case 8: motionEvent(255) break } } // now to catch stuff that is wonky else if (cmd.notificationType == 7 && cmd.eventParametersLength == 0) { switch (cmd.event) { case 3: result << createEvent(name: "acceleration", value: "active", descriptionText: "The cover was removed from $device.displayName", isStateChange: true) break case 8: motionEvent(255) break } } else { result << createEvent(descriptionText: cmd.toString(), isStateChange: false) } result }

Which just didn’t handle anything with && criteria at all…

I ended up having to do this.

`def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd) {
if (state.debug) log.debug “—NOTIFICATION REPORT V3— ${device.displayName} sent eventParametersLength: ${cmd.eventParametersLength} eventParameter: ${cmd.eventParameter} notificationType: ${cmd.notificationType} event: ${cmd.event}”
def result = []
if (cmd.notificationType == 7) {
if (cmd.event == 0x00 && cmd.eventParameter == 0x08) {
result << motionEvent(0)
}
else if (cmd.event == 0x03) {
result << createEvent(name: “acceleration”, value: “active”, descriptionText: “$device.displayName cover is open.”)
}
else if (cmd.event == 0X00 || cmd.eventParameter == 0x03) {
result << createEvent(name: “acceleration”, value: “inactive”, descriptionText: “$device.displayName cover has been closed.”)
}
else if (cmd.event == 0x08) {
result << motionEvent(255)
}
}
else {
result << createEvent(descriptionText: cmd.toString(), isStateChange: false)
}
result
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
createEvent(descriptionText: cmd.toString(), isStateChange: false)
}`

I had to use the eventParametersLength output on the last bit to handle exceptions. The developers in some cases didn’t bother passing the eventParameter. Also good to not I couldn’t use standard java string length checking on the parameter… then I noticed the length parameter… so… anyway, I know the second code block is written a bit differently, and I’d like to use the cases and maybe I could but that is what I ended up with and it works.

Am I right in assuming we can’t compare multiple parameters with && operator or did I just totally fudge it somehow?

thanks for any help!


(David) #2

Just curious but did you try forcing order of precedence?

Meaning
if (cmd.eventParameter == 3 && cmd.notificationType == 7)

becomes
if (cmd.eventParameter == 3 && (cmd.notificationType == 7))


(Robert Vandervoort) #3

No… I didn’t even know that was a thing. I mean in math it is but… Ok I will give that a whack.