Name conflict - schedule() and Thermostat schedule

I would like to use the schedule() function in an event handler to set up a recurring call. The event handler implements the Thermostat capability which has an attribute call "schedule". I get an error message that says "Cannot read write-only property: schedule" Any idea how to specify that I mean the function and not the attribute?

This might be easier for someone to troubleshoot if you provide a minimal example that produces the error, unless someone happens to have tried this exact same thing before and also ran in to the problem. I know I haven't, so it would be easier for me, at least. :smiley:

You can resolve this temporarily by adding the method below somewhere in your code:

def getSchedule(){
    
}

The setSchedule() method is confusing groovy as it automatically considers that a write-only property in the class. When checking to call the real method for schedule, it encounters this "property" first and throws an exception trying to examine it when trying to figure out what to call next.

Adding the method above causes it go past this check and call the real method for schedule.

@gopher.ny, maybe a future platform update can prevent this conflict between internal methods and the auto-property groovy mechanism for commands with the same name.

3 Likes

That worked.

This comes from Groovy itself, and messing with Groovy's default way of handling things has a long list of potential side effects. Having worked mostly with static typed languages, I understand why this is annoying, but given the effort involved in testing platform and all apps/drivers (including community) for a change like this, it's very unlikely to happen.

But "schedule" is only an attribute of the Thermostat capability. So, in code, it would always appear in quotes. The command associated with that attribute is setSchedule. So, you shouldn't be seeing a conflict with the capability at all, unless this is a user driver that doesn't follow the capability standards.

Maybe I shouldn't have been seeing it, but I was. The schedule command worked fine until I modified it to implement the Thermostat capability, which is when I started getting the error message.

Is the command in your driver "schedule" or "setSchedule"? "setSchedule" is what is included in the capability, according to the documentation. If you're seeing "schedule" then that's not what's documented.

The Thermostat capability has a command named "setSchedule" and an attribute named "schedule". The name conflict appears to be occurring with the attribute.

But, like I said, attributes always appear in double quotes. Methods do not. So, I don't see how they could be conflicting. Can you show me an example?

I don't want to spend more time on this topic since jp0550 has provided a work-around that solved my problem. If you have a driver that uses the schedule() function, try adding the Thermostat capability and let us know if that works the way you expect it to.

Although attributes appear in double quotes when you are actually attempting to refer to them, apparently groovy thinks, incorrectly, that you are trying to refer to the attribute even when you don't use double quotes. It gives an error message because you are not allowed to do what it thinks you are trying to do.