Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable config validation for thing creation and update #2682

Merged
merged 3 commits into from
Jan 20, 2022

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented Jan 13, 2022

Fixes #2674

Depends on #2683

Signed-off-by: Jan N. Klug github@klug.nrw

@J-N-K J-N-K requested a review from a team as a code owner January 13, 2022 19:53
@wborn wborn added the enhancement An enhancement or new feature of the Core label Jan 15, 2022
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Jan N. Klug <github@klug.nrw>
@J-N-K J-N-K force-pushed the feature-thing-config-validation branch from 2f9ebbe to 429c0a4 Compare January 15, 2022 14:07
Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this improvement and for streamlining the configuration validation.

I left two minor comments.

setThingStatus(thing,
buildStatusInfo(ThingStatus.UNINITIALIZED,
ThingStatusDetail.HANDLER_CONFIGURATION_PENDING,
"Missing or invalid configuration."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the ThingStatusInfo is translatable I am wondering if we should introduce a custom translation key for this description (e.g.@text/missing-or-invalid-configuration).

Copy link
Member Author

@J-N-K J-N-K Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where Do I have to place the correct value then? ThingManagerImpl.properties in the i18n-folder? Or ThingStatusInfo.properties?

Copy link
Contributor

@cweitkamp cweitkamp Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be placed into a new properties file with name SystemThingStatusInfos.properties.

"Thing '{}' not initializable, check if required configuration parameters are present and set values are valid.",
thing.getUID());
setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED,
ThingStatusDetail.HANDLER_CONFIGURATION_PENDING, "Missing or invalid configuration."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same custom key here.

Signed-off-by: Jan N. Klug <github@klug.nrw>
Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my side.

@cweitkamp cweitkamp merged commit 1fff165 into openhab:main Jan 20, 2022
@cweitkamp cweitkamp added this to the 3.3 milestone Jan 20, 2022
@J-N-K J-N-K deleted the feature-thing-config-validation branch January 20, 2022 12:44
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/my-z-wave-is-borked/132448/15

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/my-z-wave-is-borked/132448/40

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/z-wave-handler-configuration-pending-with-oh-3-3-snapshot/132549/2

try {
configDescriptionValidator.validate(configuration.getProperties(), configDescriptionURI);
} catch (ConfigValidationException e) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a trace log here to allow users to see validation messages in the log file? This might help to find the culprit for #2710.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2711

@J-N-K
Copy link
Member Author

J-N-K commented Jan 29, 2022

Yes, I‘ll prepare that immediately. It seems that at least some of the issues arise from signed/unsigned byte/int values. I‘ll check if that is a problem in the code or in the affected binding.

@petero-dk
Copy link

I am online and have this issue, so let me know how I can help

@@ -558,6 +556,7 @@ public void thingUpdated(final Thing thing, ThingTrackerEvent thingTrackerEvent)
// called from the thing handler itself, therefore
// it exists, is initializing/initialized and
// must not be informed (in order to prevent infinite loops)
// we assume the handler knows what he's doing and don't check config validity
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this assumption is wrong as e.g. the ZWave handler updates the configuration with values outside of the valid range. @cweitkamp shall we add a validation here, too? And what shall happen if the thing handler tries to update with an invalid configuration? Log a warning and deny replacing the thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. Both methods in BaseThingHandler which allows to update the configuration of a thing (updateThing(Thing) and updateConfiguration(Configuration)) lead to an unchecked configuration. There is no validation done.

Both updateThing() and updateConfiguration() call ThingHandlerCallback.thingUpdated() -> ThingRegistry.updated() -> ThingTracker.thingUpdated() of ThingManagerImpl.

In theorie we have to to check for a changed configuration of the thing and do the same like the ThingResource: call ThingRegistry.updateConfiguration() instead of just replacing the thing here. imo the handler has to be reinitialized if configuration will change.

Or did I miss something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this assumption is wrong

I think the problem with this assumption is that the binding doesn't have access to the config description, so it isn't (easily) possible for it to do this as far as I can see. The framework only passes the values to the binding - maybe it should also make the descriptions more readily available as well now that we're enforcing these checks.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-3-milestone-discussion/132715/40

splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
…ab#2682)

* Enable config validation for thing creation and update

Signed-off-by: Jan N. Klug <github@klug.nrw>
GitOrigin-RevId: 1fff165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
6 participants