-
-
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
Fix Color Temperature conversion of values represented in Celsius #18118
Comments
Wouldn't it be a better solution to make it stop throwing that exception instead? ;-) |
Your suggestion is quite correct. And the issue is definitely in our own code (link below) where in the case of Celsius or Fahrenheit the => So this seems indeed to be a bug in OH core!! @maniac103 good catch! However I am not sure the proper way forward. It would be easy enough just to plug in a hard coded fix for colour temperature. However I think probably the code should really fix the issue for all units. And/or there may be some maintainers who prefer for this case to actually continue to throw an exception here?? PS test cases are here..
|
By the way -- for the avoidance of doubt -- the REVERSE conversions do NOT throw an exception for Celsius or Fahrenheit!
|
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/openhab-4-3-milestone-discussion/158139/123 |
For completenesss, the exception thrown is
The non-linearity happens because Celsius is defined as Kelvin + offset and thus the inverse of it becomes non-linear. However, since (judging from Javadoc |
I'm by no means an expert on color temperature and corresponding units, but IMO core code is correct here. |
First question, is Color Temperature expressed in Celcius or Fahrenheit a real thing (does it make sense, is it used anywhere outside of OH), or is this because the unit is not properly set in the users' configuration in openHAB? It is very tricky for temperatures in general, as the reference point is not the same for the different temperature units. I spent quite a bit of time to come up with some reasonble logic when doing temperature calculations in OH (openhab/openhab-core#3792), which illustrates the difficulty. I was trying to preserve commutativity and distributivity of math operations on temperatures with different unit (while losing distributivity in some cases along the way). And obviously none of this is preserved when you bring mireds in the mix. I believe that only a conversion from Kelvin to Mired makes sense. Which means if we need to support it for Celcius, we may have to take care of always converting to Kelvin before doing this. But I would actually opt to catch the error and write a warning in the log that the item does not have the right unit in the first place. And I hate to say this, and I understand why invertible units have been created to be in the same dimension, but this is yet another example where the assumption that an inverted unit is of the same dimension is a stretch. It breaks normal math logic on values in the dimension. |
You guys may want to have a look at the proposed PR to fix this in OH Core |
Affects the following PRs
The above-mentioned PRs added code to convert color temperature UoM values from
Kelvin
toMirek
. However this overlooked a potential problem when the user would have a color temperature item that (wrongly) represents its color temperature inCelsius
(or probably alsoFahrenheit
).Whereas the conversion
Kelvin
=>Mirek
works fine, the conversionCelsius
=>Mirek
throws an exception. The solution is to convert such values in two steps as followsCelsius
=>Kelvin
=>Mirek
.The text was updated successfully, but these errors were encountered: