Skip to content

Commit

Permalink
[transform.vat] Suppress warnings for NULL/UNDEF (openhab#15089)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Thomas Burri <[email protected]>
  • Loading branch information
jlaur authored and tburri-alstom committed Jun 19, 2023
1 parent c77a58a commit b502c57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.transform.TransformationException;
import org.openhab.core.transform.TransformationService;
import org.openhab.core.types.UnDefType;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,6 +43,9 @@ public class VATTransformationService implements TransformationService {
try {
source = new QuantityType<>(sourceString);
} catch (IllegalArgumentException e) {
if (UnDefType.NULL.toString().equals(sourceString) || UnDefType.UNDEF.toString().equals(sourceString)) {
return sourceString;
}
logger.warn("Input value '{}' could not be converted to a valid number", sourceString);
throw new TransformationException("VAT Transformation can only be used with numeric inputs", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
import org.openhab.core.types.UnDefType;
import org.openhab.transform.vat.internal.config.VATConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -84,18 +85,21 @@ public void onStateUpdateFromHandler(State state) {

private Type transformState(Type state) {
String result = state.toFullString();
String percentage = getVATPercentage();
try {
result = TransformationHelper.transform(service, getVATPercentage(), "%s", result);
result = TransformationHelper.transform(service, percentage, "%s", result);
} catch (TransformationException e) {
logger.warn("Could not apply '{}' transformation on state '{}' with value '{}'.", PROFILE_TYPE_UID.getId(),
state, getVATPercentage());
state, percentage);
}
Type resultType = state;
if (result != null) {
if (state instanceof DecimalType) {
resultType = DecimalType.valueOf(result);
} else if (state instanceof QuantityType) {
resultType = QuantityType.valueOf(result);
} else if (state instanceof UnDefType) {
resultType = UnDefType.valueOf(result);
}
logger.debug("Transformed '{}' into '{}'", state, resultType);
}
Expand Down

0 comments on commit b502c57

Please sign in to comment.