openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
218 stars 238 forks source link

Textual Item import fails if there are multiple links #878

Open kaikreuzer opened 3 years ago

kaikreuzer commented 3 years ago

The problem

I am trying to use "Add Items from Textual Definition". My item definition has multiple links:

Dimmer Light_Ceiling "Deckenlicht" <light> { channel="hue:0220:1:20:brightness,knx:device:ip:knx_1_1_1:3" }

UI shows the message:

Screenshot 2021-02-05 at 11 15 25

Expected behavior

Item and two links are created.

Steps to reproduce

  1. Add above item example to the import in the main UI.

Your environment

Distro build 2182

Browser console

Shows HTTP 500 server error

Browser network traffic

HTTP 500 is returned by the call to /rest/links/Light_Ceiling/hue%3A0220%1%3A20%3Abrightness%2Cknx%3Adevice%3Aip%3Aknx_1_1_1%3A3 which results in an exception on server side:

"{\"error\":{\"message\":\"ID segment \\u00271b,knx\\u0027 contains invalid characters. Each segment of the ID must match the pattern [\\\\w-]*.\",\"http-code\":500,\"exception\":{\"class\":\"java.lang.IllegalArgumentException\",\"message\":\"ID segment \\u00271b,knx\\u0027 contains invalid characters. Each segment of the ID must match the pattern [\\\\w-]*.\",\"localized-message\":\"ID segment \\u00271b,knx\\u0027 contains invalid characters. Each segment of the ID must match the pattern [\\\\w-]*.\"}}}"

Additional information

It seems that the UI needs to split the string at every comma and do multiple PUT requests for creating the links.

kaikreuzer commented 3 years ago

FTR, I have created https://github.com/openhab/openhab-core/pull/2179 to make the REST API return a 400 instead of a 500 in future.

cweitkamp commented 3 years ago

https://github.com/openhab/openhab-core/pull/2179 has been merged.

ghys commented 3 years ago

@kaikreuzer I just had a look and it seems that this syntax as documented in https://www.openhab.org/docs/configuration/items.html#multi-binding-channel-linkage works correctly:

Dimmer Light_Ceiling "Deckenlicht" <light> { channel="hue:0220:1:20:brightness" [ profile="abc" ], channel="knx:device:ip:knx_1_1_1:3" [ profile="def" ] }

with the added benefit that it allows to set the individual links' config, like different profiles.

I don't seem to find any documented example of the comma-separated channels in a single string value, and was unaware it was supported. Is it still relevant with the consideration above (unable to set a different configuration per link). If so how should an eventual configuration reflected in the (multiple) links in that case, like {channel="channel1,channel2" [ config="value" ]} - it turns out to be less trivial than expected!

kaikreuzer commented 3 years ago

The comma separated syntax was the original one and has been always supported already - and it is imho also much nicer in most cases as it feels slightly weird to have the same key occurring multiple times. Would hence be nice to see it supported in the import as well.

If so how should an eventual configuration reflected in the (multiple) links in that case

The configuration should be applied to all channels in the list. That's how it is processed in the GenericItemChannelLinkProvider, which parses this part of the DSL files.