Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Ecobee binding bug: BigDecimal needs precision/rounding when converting to/from Celsius #2793

Merged
merged 1 commit into from
Jun 29, 2015

Conversation

watou
Copy link
Contributor

@watou watou commented Jun 24, 2015

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.

@watou
Copy link
Contributor Author

watou commented Jun 25, 2015

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.

@watou
Copy link
Contributor Author

watou commented Jun 26, 2015

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));
Copy link
Contributor

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

Copy link
Contributor Author

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!

Copy link
Member

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?

@teichsta teichsta added bug and removed in progress labels Jun 29, 2015
@teichsta teichsta added this to the 1.7.1 milestone Jun 29, 2015
teichsta added a commit that referenced this pull request Jun 29, 2015
Ecobee binding bug: BigDecimal needs precision/rounding when converting to/from Celsius
@teichsta teichsta merged commit 0664def into openhab:master Jun 29, 2015
@teichsta
Copy link
Member

Thanks @watou!

@watou watou deleted the ecobee-celsius-arithmetic-exception branch June 29, 2015 21:15
@watou
Copy link
Contributor Author

watou commented Jun 29, 2015

Will simply conversion in #2755 as suggested. Thanks @teichsta.

watou added a commit to watou/openhab that referenced this pull request Jul 22, 2015
* 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)
watou added a commit to watou/openhab that referenced this pull request Jul 28, 2015
* 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)
watou added a commit to watou/openhab that referenced this pull request Jul 31, 2015
* 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)
watou added a commit to watou/openhab that referenced this pull request Aug 23, 2015
* 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.
watou added a commit to watou/openhab that referenced this pull request Aug 26, 2015
* 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.
paolodenti pushed a commit to paolodenti/openhab that referenced this pull request Sep 28, 2015
* 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.
paolodenti pushed a commit to paolodenti/openhab that referenced this pull request Oct 1, 2015
* 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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants