stefan-kaestle / openhab2-addons

Add-ons for openHAB 2.x
Eclipse Public License 2.0
16 stars 1 forks source link

Prevent creation of Thing without assigning a parent bridge #63

Closed MarkJonas closed 3 years ago

MarkJonas commented 3 years ago

Right now (v1.0-beta.5) it is possible to create a Thing (e.g. TwinGuard) without assigning a parent bridge.

It would be great if there was no parent bridge selected and the user presses the Create Thing button an error text would be shown and the Parent Bridge field would be highlighted.

I systematically forgot to assign the parent bridge to most of my five TwinGuards when setting them up. For most I quickly found the problem because the Thing went from online to offline quickly. But one stayed online (for unknown reasons) but did not receive measurements. Finally I realized that the bridge was missing.

coeing commented 3 years ago

I had a look at this issue, but I can't find any way to make setting the bridge mandatory/required. @MarkJonas Do you use other bindings and could check if they show an error if no bridge is set? For me it looks like this is missing in openHAB itself and we can not work around that limitation.

coeing commented 3 years ago

Just as an addition: The place this should be setup would be thing-types.xml where the relationship between a thing and the bridge is made like this:

    <thing-type id="in-wall-switch">
        <supported-bridge-type-refs>
            <bridge-type-ref id="shc"/>
        </supported-bridge-type-refs>
MarkJonas commented 3 years ago

@coeing I tried jeelink:lacrosse, homeconnect:coffeemaker, and boschshc:in-wall-switch. None gives an error when creating a thing and forgetting to select the bridge. But the way how the problem is communicated after creation is different.

jeelink

In the things list the jeelink:lacrosse will show as ERROR: HANDLER. When clicking on the thing it will be UNINITIALZED with the following error description:

HANDLER_INITIALIZING_ERROR

homeconnect

In the things list the homeconnect:coffeemaker will show as ERROR: BRIDGE. When clicking on the thing it will be OFFLINE with the following error description:

BRIDGE_OFFLINE

boschshc

In the things list the boschshc:in-wall-switch will show as ERROR: CONFIG. When clicking on the thing it will be OFFLINE with the following error description:

CONFIGURATION_ERROR
No valid bridge set for org.openhab.core.thing.internal.ThingImpl@4dbd3dd7

Conclusion

From the implementations I checked I think the boschshc way is the preferred way until the openHAB framework is able to check for mandatory configuration settings. IMHO not setting the bridge is a configuration error and the verbose error message clearly states the bridge setting setting is the problem.

Do you plan to communicate the missing possibility to check for mandatory configuration settings to the openHAB main project?

coeing commented 3 years ago

@MarkJonas Thanks for your documentation how the other plugins work :) I think the best way for us would be to open an issue in the main openHAB repository about this missing feature. Maybe there is already an issue in their issue tracker about it.

From our side we could only add a better identifier for the thing that is missing the bridge, but other than that I see no possibility to improve the behaviour ourselves :/

GerdZanker commented 3 years ago

From our side we could only add a better identifier for the thing that is missing the bridge,

+1

but other than that I see no possibility to improve the behaviour ourselves :/

Its not finished, but with the #27 "Discovery" the bridge will be set automatically and avoids this issue

coeing commented 3 years ago

I opened an issue in the openHAB addons issue tracker, let's see if there will be some response to it :)

In the meantime I will change the error message to have a better identifier for the thing.