diff --git a/bundles/org.openhab.transform.map/src/main/java/org/openhab/transform/map/internal/profiles/MapTransformationProfile.java b/bundles/org.openhab.transform.map/src/main/java/org/openhab/transform/map/internal/profiles/MapTransformationProfile.java index 31af32e6094d8..872e536585427 100644 --- a/bundles/org.openhab.transform.map/src/main/java/org/openhab/transform/map/internal/profiles/MapTransformationProfile.java +++ b/bundles/org.openhab.transform.map/src/main/java/org/openhab/transform/map/internal/profiles/MapTransformationProfile.java @@ -17,12 +17,13 @@ import org.openhab.core.thing.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; import org.openhab.core.thing.profiles.ProfileTypeUID; -import org.openhab.core.thing.profiles.StateProfile; +import org.openhab.core.thing.profiles.TimeSeriesProfile; import org.openhab.core.transform.TransformationException; import org.openhab.core.transform.TransformationHelper; import org.openhab.core.transform.TransformationService; import org.openhab.core.types.Command; import org.openhab.core.types.State; +import org.openhab.core.types.TimeSeries; import org.openhab.core.types.Type; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,7 @@ * @author Stefan Triller - Initial contribution */ @NonNullByDefault -public class MapTransformationProfile implements StateProfile { +public class MapTransformationProfile implements TimeSeriesProfile { public static final ProfileTypeUID PROFILE_TYPE_UID = new ProfileTypeUID( TransformationService.TRANSFORM_PROFILE_SCOPE, "MAP"); @@ -113,6 +114,21 @@ public void onStateUpdateFromHandler(State state) { callback.sendUpdate((State) transformState(state)); } + @Override + public void onTimeSeriesFromHandler(TimeSeries timeSeries) { + if (function == null || sourceFormat == null) { + logger.warn( + "Please specify a function and a source format for this Profile in the '{}' and '{}' parameters, e.g \"translation.map\" and \"%s\". Returning the original state now.", + FUNCTION_PARAM, SOURCE_FORMAT_PARAM); + callback.sendTimeSeries(timeSeries); + return; + } + TimeSeries transformedTimeSeries = new TimeSeries(timeSeries.getPolicy()); + timeSeries.getStates() + .forEach(entry -> transformedTimeSeries.add(entry.timestamp(), (State) transformState(entry.state()))); + callback.sendTimeSeries(transformedTimeSeries); + } + private Type transformState(Type state) { String result = state.toFullString(); try {