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;
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);
}
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;
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) {
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);
}