-
Notifications
You must be signed in to change notification settings - Fork 26
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
[transform.math] Fix missing unit when result is 0 #507
Conversation
Signed-off-by: clinique <gael@lhopital.org>
try { | ||
source = new QuantityType<>(sourceString); | ||
} catch (IllegalArgumentException e) { | ||
logger.warn("Input value '{}' could not be converted to a valid number", sourceString); | ||
throw new TransformationException("Math Transformation can only be used with numeric inputs"); | ||
} | ||
QuantityType<?> value; | ||
String evaluated = sourceString; | ||
try { | ||
value = new QuantityType<>(valueString); | ||
source = new QuantityType<>(evaluated); | ||
evaluated = valueString; | ||
value = new QuantityType<>(evaluated); | ||
} catch (IllegalArgumentException e) { | ||
logger.warn("Input value '{}' could not be converted to a valid number", valueString); | ||
logger.warn("Input value '{}' could not be converted to a valid number", evaluated); | ||
throw new TransformationException("Math Transformation can only be used with numeric inputs"); | ||
} |
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 did you change that?
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.
To avoid having two catch catching the same thing....could be avoided.
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.
Reverted
QuantityType<?> result = performCalculation(source, value); | ||
return BigDecimal.ZERO.compareTo(result.toBigDecimal()) == 0 ? "0" : result.toString(); | ||
return performCalculation(source, value).toString(); |
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 See why it works now, but I wonder why it was done like that before. Maybe to prevent a return value of 0.0000
?
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.
Yes, I was wondering the same, reason why I wanted your advice.
Signed-off-by: clinique <gael@lhopital.org>
* Code modification proposal following issue smarthomej#506 Signed-off-by: clinique <gael@lhopital.org> Signed-off-by: Jan N. Klug <github@klug.nrw>
Resolves #506