Skip to content

TypeParser and OnOffType #2232

Open
Open
@falmanna

Description

@falmanna

I was debugging a NullPointerException returned from TypeParser.parseCommand function when I tried to parse a command string of value "1" for a SwitchItem item. I found that the OnOffType doesn't have a valueOf method and it is relying on the Enum.valueOf to parse string commands. That means only "ON" and "OFF" strings will be parsed.

Although the OnOffType has a from method that accepts a string of "1", it seems to never get called anywhere. So, was it supposed to be valueOf instead? or is it removed from this type intentionally?

I propose a change to the method from to be valueOf, and to add a third option to parse "true" to "ON"
So, this will become this:

public static OnOffType valueOf(String state) {
        return from("ON".equalsIgnoreCase(state) || "1".equalsIgnoreCase(state) || "true".equalsIgnoreCase(state));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions