-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ecobee binding bug: BigDecimal needs precision/rounding when converting to/from Celsius #2793
Ecobee binding bug: BigDecimal needs precision/rounding when converting to/from Celsius #2793
Conversation
… converting to/from Celsius.
Initial bug report and report of fix working. Let's wait to hear one final report in a day or two before you would consider merging, Thomas. And thanks. |
User reports that this fix is solid. If you don't disagree, can this be included in 1.7.1, @teichsta ? (This same change is included in the PR that adds the action bundle.) Thank you, Thomas! |
@@ -132,7 +133,7 @@ public static Temperature fromFahrenheit(BigDecimal fahrenheit) { | |||
* the Celsius temperature | |||
*/ | |||
public static Temperature fromCelsius(BigDecimal celsius) { | |||
return new Temperature(celsius.multiply(NINE).divide(FIVE).add(THIRTY_TWO).movePointRight(1)); | |||
return new Temperature(celsius.multiply(NINE).divide(FIVE, MathContext.DECIMAL32).add(THIRTY_TWO).movePointRight(1)); |
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.
Why not just multiply by 1.8 instead of multiplying by 9 then dividing by 5
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.
That would make more sense. I used some BigDecimal F-to-C example from somewhere that does it this way, and most conversion examples in a Google search seem to prefer 9/5 (probably because they are explaining how to convert in your head). A single multiply would virtually certainly be faster, since there is one fewer intermediate objects created. But since I have a user who has already signed off on the current code, I will leave it unless Thomas would like me to do it differently. Thanks, Rob, for the comment!
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.
i am fine with this one for 1.7.1. You could probably change the code to 1.8 in #2755?
Ecobee binding bug: BigDecimal needs precision/rounding when converting to/from Celsius
Thanks @watou! |
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942)
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942)
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942)
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942) * changes similar to @teichsta's PR openhab#2967 so actions now appear in Designer; moved messages package out of internal; made ecobeeSetHold temp paramter truly optional.
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942) * changes similar to @teichsta's PR openhab#2967 so actions now appear in Designer; moved messages package out of internal; made ecobeeSetHold temp paramter truly optional. * Quiesce logging when network failure keeps a poll from completing.
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942) * changes similar to @teichsta's PR openhab#2967 so actions now appear in Designer; moved messages package out of internal; made ecobeeSetHold temp paramter truly optional. * Quiesce logging when network failure keeps a poll from completing.
* mult-ecobees-1-acct-bug (PR openhab#2765) * ecobee-celsius-arithmetic-exception (openhab#2793) * ecobee-discard-tokens (PR openhab#2849) * ecobee-echo-cancellation (PR openhab#2942) * changes similar to @teichsta's PR openhab#2967 so actions now appear in Designer; moved messages package out of internal; made ecobeeSetHold temp paramter truly optional. * Quiesce logging when network failure keeps a poll from completing.
Avert ArithmeticExceptions for non-terminating decimal expansion when converting to/from Celsius. I imagine very few Ecobee binding users are using Celsius, but for those that are, this fix would be required.