-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] Fix state description #16866
[MQTT] Fix state description #16866
Conversation
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
To my surprise, my Eclipse IDE has automatically refactored some explicit type casting in |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/basicui-4-2-0-m3-issue-with-uom/156700/3 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/doubled-unit-output/156591/16 |
Yes, I noticed them. A while back I changed those methods to return the specific Type for each Value, but didn't go change any of the tests. So I agree it's a good simplification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
* fix state description Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/change-the-default-state-pattern-in-4-2-x/158322/10 |
* fix state description Signed-off-by: Mark Herwege <mark.herwege@telenet.be> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
* fix state description Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
* fix state description Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
* fix state description Signed-off-by: Mark Herwege <mark.herwege@telenet.be> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
The dynamic stateDescription created by the MQTT binding always uses
%s
for all of its types.The consequence of this is that for a Number QuantityType, the full state including the unit will be returned. When retrieving the state description from the Number:Dimension item linked to that channel, another unit will be added, effectively showing the unit label twice.
See https://community.openhab.org/t/doubled-unit-output/156591 for more details about the problem.
This PR makes sure proper state descriptions, complying to the default, are returned.
At the same time, the MQTT binding currently always returns a
QuantityType<Dimensionless>
withUnit.ONE
for channels where the unit is not set. This has been changed here to returnDecimalType
instead. Without it, the state description patterns would need special handling, different from handling elsewhere, and the conversion betweenUnit.ONE
andUnit.PERCENT
could not be left to the framework. This is a change in behaviour and may impact handling with % values. But the handling in the MQTT binding at this time is inconsistent with the overall handling in OH, so I believe this change improves consistency overall.The impact of this change can be seen in the modified and extra test in
ValueTests.numberPercentageUpdate()
.