If statement issues - C-7 Hub and Ver 2.2.6

There appears to be an issue with if(condA || condB) statements on C-7 Hubs using SW version 2.2.6. It does NOT occur on C-5 nor C-4 Hubs.

Below are code extract from one of my drivers of the lines that I had to either delete or convert to single condition statements to get the code to work. In each case, the symptom was the running method immediately exiting w/o any error in the logs.
[Note: The C-7 issue was identified by another user and with his assistance, I was able to isolate the solutions.]

From preferences within metadata
original code (works on C-4 and C-5 hubs, not C-7

		if (bind && parent.kasaCloudUrl) {
			input ("useCloud", "bool",
				   title: "Use Kasa Cloud for device control",
				   defaultValue: false)
		}

Updated and works on C-7 Hub

		if (bind ) {
			input ("useCloud", "bool",
				   title: "Use Kasa Cloud for device control",
				   defaultValue: false)
		}

From method sendLanCmd
original code

	def model = getDataValue("model")
	if (model == "HS100" || model == "HS200") {
		runIn(2, socketStatus, [data: "closed"])
	} else {
		socketStatus("open")
		runIn(35, socketStatus, [data: "closed"])
	}

Updated code

	def model = getDataValue("model")
	if (model == "HS200") {
		runIn(2, socketStatus, [data: "closed"])
	} else {
		socketStatus("open")
		runIn(35, socketStatus, [data: "closed"])
	}

A link to the original source code for the driver:
"https://raw.githubusercontent.com/DaveGut/HubitatActive/master/KasaDevices/DeviceDrivers/Plug-Switch.groovy"

Is it a specific version of 2.2.6?

These all seem OK on my dev C7 which is currently running 2.2.6.129:

if (!(descriptionMap.profileId) || (descriptionMap.profileId && descriptionMap.profileId == "0104")) {

if (descriptionMap.cluster == "0006" || descriptionMap.clusterId == "0006" || descriptionMap.clusterInt == 6) {

if (descriptionMap.command == "00" || descriptionMap.command == "01") {

Maybe it's something else code specific, but it doesn't seem to be as generic as all "if(condA || condB) statements" .... I'd imagine there'd be many more people with issues if it were?

It was 2.2.6.129, The only thing changed was reducing the dual conditions to a single condition. The really pertubing issue was NO captured error. Just terminated the current method train.

A stripped sendLanCmd method works OK on this C7 with 2.2.6.129:

image

Have you reproduced it yourself? Or is it just a user report? Maybe get them to reboot the C7 and see if it still does it?

A user had the issue. I do not have a C7 Hub (C4 and C5).

I had him turn on logging and run the code, providing me the logs and page information to me for analysis..

First problem was NONE of the preferences appeared. This was corrected by simplifying the first IF Statement (modified code). That fixed preferences.

Next, when sending a command, the device did not physically respond. Examining the logs, I noted that the method train was exiting in sendLanCmd. So, following the preferences issue, I tried the same there - simplifying the if statement. It worked.

Again, what was really troubling is there were no log entries for an unexpected exit from a method train. So the issue was hard to track down.

If this were true, none of the built-in apps would work.

2 Likes

IMO a reboot and then retest is in order, to me it sounds like something is funky with that C7.

Maybe remove the device and driver code and re-import.

If there was a problem with if statements in general then the hubitat world would crumble as I'd imagine the vast majority of Apps / Drivers use || and && in them.

1 Like

yes my email app has many ifs like that.. could it be a parenthesis issue i always fully parenthesize

ie
if (!((oldState == "Sent Ok") || (oldState == "Send Failed") || (oldState == "Connection Closed") || (oldState == "quit") || (oldState == "Force Closed")))
{

Bottom line, I am glad it was not something I did wrong. But, I am still concerned that the method train was exited without any warning or other log entry (in both cases). But that is probably a very minor issue that is very hard to fix.
Dave

I think you are misunderstanding what actually happened, or didn't happen. There is no "exit method train" failure. It's just code...

1 Like

What I saw was the system apparently does not complete the method and no error is generated. Is there a nomenclature for this type of error?

Evidence is the first example where metadata defined 5 preferences; however, when the device was opened, the preferences section did not appear on the associated device's edit page. There is no error generated. That is an issue.

But I do not want to argue, so the subject is closed.