]> git.basschouten.com Git - openhab-addons.git/commitdiff
[transform.vat] Suppress warnings for NULL/UNDEF (#15089)
authorJacob Laursen <jacob-github@vindvejr.dk>
Tue, 13 Jun 2023 15:31:45 +0000 (17:31 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Jun 2023 15:31:45 +0000 (17:31 +0200)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/VATTransformationService.java
bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/profile/VATTransformationProfile.java

index a0518c8811d2d674460d1c48f519cb981dbceba4..c0db9e30b232043779b2b0eb646f5f11cd6b5029 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.Nullable;
 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;
@@ -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);
         }
index 1985d9beb5f665fb37c1752a79815a35afe9b767..73f26685f17b0a74f59f9bde5625c1e79f5bf334 100644 (file)
@@ -30,6 +30,7 @@ import org.openhab.core.transform.TransformationService;
 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;
@@ -84,11 +85,12 @@ public class VATTransformationProfile implements StateProfile {
 
     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) {
@@ -96,6 +98,8 @@ public class VATTransformationProfile implements StateProfile {
                 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);
         }