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

[mqtt.generic] fix state description provider #8990

Closed
wants to merge 1 commit into from

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented Nov 9, 2020

Fixes #8845

Signed-off-by: Jan N. Klug [email protected]

@J-N-K J-N-K added the bug An unexpected problem or unintended behavior of an add-on label Nov 9, 2020
@cpmeister
Copy link
Contributor

cpmeister commented Nov 9, 2020

I'm not sure about this, from the issue conversation it looks like the core is checking if the new state description is equal to the original description using .equals. IMO it shouldn't be an error for a binding to coincidentally return a description that happens to be similar to the original one. If the intent of the check is to make sure that the binding isn't returning the original description then perhaps the equality check in the core should be changed to a reference comparison between the original and returned descriptions.

@jochen314
Copy link
Contributor

Even the documentation says:

If the given channel will not be managed by the provider null should be returned. You never must return the 
original state description in such case.

But the implemenation will always return null if the cannel is not managed by the provider.
This is not a problem of the provider, but of the logging in the core.

@J-N-K
Copy link
Member Author

J-N-K commented Nov 12, 2020

@openhab/core-maintainers Can you comment here? It's true that the original state description is returned but the channel is managed by the provider, to the restriction is not fulfilled here.

@cweitkamp
Copy link
Contributor

cweitkamp commented Nov 12, 2020

I agree on that this implementation of the DynamicStateDeaceiptionProvider is a valid use case. And the comparison in OHC does not considered such a situation. Point is that we have to make sure in some way that no original state description will be returned by any binding if the channel is not manged by the provider because if it does it will accidently overwrite state description of other bindings.

the equality check in the core should be changed to a reference comparison between the original and returned descriptions

This is probably not possible because most of the bindings extend the BaseDynamicStateDescriptionProvider which always builds a new state description instance to provide transportation features for dynamic state options and patterns.

@cpmeister
Copy link
Contributor

the equality check in the core should be changed to a reference comparison between the original and returned descriptions

This is probably not possible because most of the bindings extend the BaseDynamicStateDescriptionProvider which always builds a new state description instance to provide transportation features for dynamic state options and patterns.

Why would them always building a new dynamic state cause problems, that is exactly what you want them to do, no?
The code change in the core should be simple:

            StateDescription stateDescription = provider.getStateDescription(channel, originalStateDescription, locale);
            if (stateDescription != null) {
                if (stateDescription == originalStateDescription) {
                    logger.error(
                            "Dynamic state description matches original state description. DynamicStateDescriptionProvider implementations must never return the original state description. {} has to be fixed.",
                            provider.getClass());
                } else {
                    return stateDescription;
                }
            }

This would guarantee that the dynamic providers are not returning the originalStateDescription that is passed in as a parameter. Any returned non-null description after the reference comparison would be guaranteed to have been intentionally supplied by the provider.

@cweitkamp
Copy link
Contributor

Yes, I was talking nonsense yesterday. I will do some test later this day.

@cweitkamp
Copy link
Contributor

I submitted openhab/openhab-core#1817 to fix #8845. This PR will not be needed anymore.

@J-N-K J-N-K closed this Nov 13, 2020
@J-N-K J-N-K deleted the mqtt-statedescriptionprovider branch November 13, 2020 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
4 participants