I was reading through the code to try to learn more about how association groups work, and I found what appears to be a bug in the 4-in-1 sensor driver. I didn't look to see if the same bug is present in other drivers as well.
|
state."desiredAssociation${group}" = nodes |
If state."desiredAssociation${group}" is null, the condition at the beginning of the function which seems designed to avoid a null pointer exception is assuming that the method was called with an attempt to add nodes, not remove them. That's probably true, but not necessarily; you can never fully predict what the user will try to do. As a consumer of the code, I find this behavior counter to what I'd expect. I'd expect an attempt to remove nodes from a null list to either be a no-op or an error.
I think it would be really easy to fix this to be a no-op, using the groovy "elvis" operator ?:. Just replace the entire method body with this:
switch (action) {
case 0:
state."desiredAssociation${group}" = state."desiredAssociation${group}" ?: [] - nodes
break
case 1:
state."desiredAssociation${group}" = state."desiredAssociation${group}" ?: [] + nodes
break
}
Note: I haven't tested this.
I was reading through the code to try to learn more about how association groups work, and I found what appears to be a bug in the 4-in-1 sensor driver. I didn't look to see if the same bug is present in other drivers as well.
Hubitat/Drivers/inovelli-4-in-1-sensor.src/inovelli-4-in-1-sensor.groovy
Line 704 in 1b6a550
If
state."desiredAssociation${group}"isnull, the condition at the beginning of the function which seems designed to avoid a null pointer exception is assuming that the method was called with an attempt to add nodes, not remove them. That's probably true, but not necessarily; you can never fully predict what the user will try to do. As a consumer of the code, I find this behavior counter to what I'd expect. I'd expect an attempt to remove nodes from a null list to either be a no-op or an error.I think it would be really easy to fix this to be a no-op, using the groovy "elvis" operator
?:. Just replace the entire method body with this:Note: I haven't tested this.