Page 1 of 1

Set Error State not working

PostPosted: Mon Mar 27, 2023 6:55 am
by racarter
I have the following code in a plugin:

Code: Select all
                            if muted:
                                dev.description = "MUTED"
                                dev.replaceOnServer()
                                dev.setErrorStateOnServer("Error")
                            else:
                                dev.description = ""
                                dev.replaceOnServer()
                                dev.setErrorStateOnServer(None)

When the code runs, if muted is True the Notes field shows the word "MUTED" but the device does not turn red or show the "Error" text.

Any suggestions gratefully received!

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 10:56 am
by jay (support)
I'm not seeing that behavior - I wonder if maybe there's a race condition. Try doing the setErrorStateOnServer before doing the replaceOnServer call.

[MODERATOR NOTE]: moved topic to the sdk support forum

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 11:58 am
by racarter
Same result Jay.

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 12:02 pm
by DaveL17
Shot in the dark -- any chance the device in question is not owned by your plugin?

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 12:03 pm
by racarter
Definitely mine Dave!

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 12:32 pm
by jay (support)
Reload the plugin in an interactive shell, get the dev instance, then try to set the error state that way.

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 1:06 pm
by racarter
OK, this is weird.

I've added code to check the device props immediately before and after setting the error state. Before the set statement it shows "errorState: " and after it shows "errorState: Error" as it should, but next time through the code the 'before' check shows errorState blank again - in other words, the set error is not being remembered. My plugin has no other set error statements (I've commented out the error clearing code).

Re: Set Error State not working

PostPosted: Mon Mar 27, 2023 5:37 pm
by jay (support)
That is very odd. Pretty sure there's something in your plugin that's resetting it. I wonder if that section of code is getting called twice, once with muted True followed by False?

Re: Set Error State not working

PostPosted: Tue Mar 28, 2023 12:37 am
by racarter
The only setErrorStateOnServer statement is the one that sets it to “Error”. There are no others - I have them commented out. Is there any other call which could reset the error state?

Re: Set Error State not working

PostPosted: Tue Mar 28, 2023 2:34 am
by autolog
racarter wrote:
The only setErrorStateOnServer statement is the one that sets it to “Error”. There are no others - I have them commented out. Is there any other call which could reset the error state?

Yes, any subsequent device update will reset the error state.

From the documentation for updateStateOnServer(key='keyName', value='Value', clearErrorState=True):
Use this method to update the value of one of your device's states on the server. The server will propagate the change out to any connected clients and fire any triggers that are defined on that state. Pass “true” (default) or “false” on the clearErrorState parameter (not required) to have the error state of the device (set with setErrorStateOnServer above) cleared.

Re: Set Error State not working

PostPosted: Tue Mar 28, 2023 3:08 am
by racarter
Thanks Jon, I’d read that, but I don’t include the clearErrorState parameter in my updates. Unless Indigo defaults to clearErrorState = True in the absence of a specific declaration?

Re: Set Error State not working (RESOLVED)

PostPosted: Tue Mar 28, 2023 3:19 am
by racarter
Yep. Turns out you have to explicitly include clearErrorState=False in any device updates to avoid resetting the error state.

Re: Set Error State not working (RESOLVED)

PostPosted: Tue Mar 28, 2023 4:03 am
by autolog
racarter wrote:
Yep. Turns out you have to explicitly include clearErrorState=False in any device updates to avoid resetting the error state.

Yes, that's why the docs say ... Pass “true” (default) ... when referring to the clearErrorState parameter. :wink:

Re: Set Error State not working

PostPosted: Tue Mar 28, 2023 10:11 am
by jay (support)
Right. The most common use-case is that some error occurs, so an update to a device won't happen again until the error condition is resolved. Obviously, that's just the common use-case, we added the flag so that you could maintain the error state through device updates if you wanted.