Skip to content

Generated DSL syntax for Things file invalid #4652

Open
@jlaur

Description

@jlaur

When discovering this Thing:

Image

clicking it and selecting "Copy DSL Definition", the following output is generated:

Thing danfossairunit:airunit:"-1062731542" [host="ccm.local"]

Putting this into a .things file will result in the following error:

2025-03-17 21:09:46.503 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'danfoss2.things'
2025-03-17 21:09:46.508 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'danfoss2.things' has errors, therefore ignoring it: [1,30]: missing RULE_ID at '"-1062731542"'

After manually removing the quotes:

Thing danfossairunit:airunit:-1062731542 [host="ccm.local"]

this is the result:

2025-03-17 21:11:44.748 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'danfoss2.things'
2025-03-17 21:11:44.752 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'danfoss2.things' has errors, therefore ignoring it: [1,30]: extraneous input '-' expecting RULE_ID

It looks like DSL doesn't accept this syntax, although it does appear to be a valid ThingUID:

private static final Pattern SEGMENT_PATTERN = Pattern.compile("[\\w-]*");

public static boolean isValid(@Nullable String segment) {
return segment != null && SEGMENT_PATTERN.matcher(segment).matches();
}
protected void validateSegment(String segment, int index, int length) {
if (!isValid(segment)) {
throw new IllegalArgumentException(String.format(
"ID segment '%s' contains invalid characters. Each segment of the ID must match the pattern %s.",
segment, SEGMENT_PATTERN));
}
}

So either the UID validation is not strict enough, or the DSL validation is too strict?

Related to #4569, but also has UI impact here where none of the buttons can be clicked:

Image

Expected Behavior

Either validateSegment should throw:

public static boolean isValid(@Nullable String segment) {
return segment != null && SEGMENT_PATTERN.matcher(segment).matches();
}
protected void validateSegment(String segment, int index, int length) {
if (!isValid(segment)) {
throw new IllegalArgumentException(String.format(
"ID segment '%s' contains invalid characters. Each segment of the ID must match the pattern %s.",
segment, SEGMENT_PATTERN));
}
}

Or it should be possible to provide this ThingUID in a .things file.

Current Behavior

This constructor:

/**
* Instantiates a new thing UID.
*
* @param thingTypeUID the thing type
* @param id the id
*/
public ThingUID(ThingTypeUID thingTypeUID, String id) {
super(thingTypeUID.getBindingId(), thingTypeUID.getId(), id);
}

accepts:

new ThingTypeUID("danfossairunit", "airunit"), "-123"

Possible Solution

TBD.

Steps to Reproduce (for Bugs)

See above.

In 4.3 the UI allowed to add this ThingUID as a managed Thing:

Image

Image

Also it was accepted when manually creating a Thing:

Image

whereas in 5.0:

Image

This is related to openhab/openhab-webui#3059

Context

I'm working on the Danfoss Air Unit binding, and found this old oddness:

https://github.com/openhab/openhab-addons/blob/379b244b1f73bf7dde89990e2a3b9f00265fb04b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/discovery/DanfossAirUnitDiscoveryService.java#L142

I can easily fix this in case the outcome of this issue is that the ThingUID validation is made more strict.

Your Environment

  • Version used: 5.0 snapshot 4547

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions