use of org.openhab.core.transform.TransformationException in project openhab1-addons by openhab.
the class OpenEnergyMonitorBinding method transformData.
/**
* Transform received data by Transformation service.
*
*/
protected org.openhab.core.types.State transformData(String transformationType, String transformationFunction, org.openhab.core.types.State data) {
if (transformationType != null && transformationFunction != null) {
String transformedResponse = null;
try {
TransformationService transformationService = TransformationHelper.getTransformationService(OpenEnergyMonitorActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, String.valueOf(data));
} else {
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable", transformationType);
}
} catch (TransformationException te) {
logger.error("transformation throws exception [transformation type=" + transformationType + ", transformation function=" + transformationFunction + ", response=" + data + "]", te);
}
logger.debug("transformed response is '{}'", transformedResponse);
if (transformedResponse != null) {
return new DecimalType(transformedResponse);
}
}
return data;
}
use of org.openhab.core.transform.TransformationException in project openhab1-addons by openhab.
the class FatekNumberItem method getStateWithTransformation.
private State getStateWithTransformation(BigDecimal val) {
TransformationService transformationService = TransformationHelper.getTransformationService(FatekPLCActivator.getContext(), transType);
String strVal = String.valueOf(val);
String transOut;
if (transformationService != null) {
try {
transOut = transformationService.transform(transFunc, strVal);
logger.debug("transOut={}", transOut);
} catch (TransformationException e) {
transOut = null;
logger.warn("Transformation error: {}", e.getMessage());
}
} else {
transOut = null;
logger.warn("No transformation service for: {}", transType);
}
if (transOut != null && !"null".equals(transOut)) {
strVal = transOut;
}
return new DecimalType(strVal);
}
use of org.openhab.core.transform.TransformationException in project openhab1-addons by openhab.
the class ExecBinding method transformResponse.
protected String transformResponse(String response, String transformation) {
String transformedResponse;
try {
String[] parts = splitTransformationConfig(transformation);
String transformationType = parts[0];
String transformationFunction = parts[1];
TransformationService transformationService = TransformationHelper.getTransformationService(ExecActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, response);
} else {
transformedResponse = response;
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable", transformationType);
}
} catch (TransformationException te) {
logger.error("transformation throws exception [transformation=" + transformation + ", response=" + response + "]", te);
// in case of an error we return the response without any
// transformation
transformedResponse = response;
}
logger.debug("transformed response is '{}'", transformedResponse);
return transformedResponse;
}
Aggregations