From e77a4a6627fcbc4b30a73978989db0362b36b6f0 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Thu, 9 Nov 2023 18:00:23 +0100 Subject: [PATCH] Implement TimeSeriesProfile Signed-off-by: Jacob Laursen --- .../internal/profile/VATTransformationProfile.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/profile/VATTransformationProfile.java b/bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/profile/VATTransformationProfile.java index d95813227aec5..60b8bed26fe45 100644 --- a/bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/profile/VATTransformationProfile.java +++ b/bundles/org.openhab.transform.vat/src/main/java/org/openhab/transform/vat/internal/profile/VATTransformationProfile.java @@ -23,12 +23,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.openhab.core.types.UnDefType; import org.openhab.transform.vat.internal.config.VATConfig; @@ -41,7 +42,7 @@ * @author Jacob Laursen - Initial contribution */ @NonNullByDefault -public class VATTransformationProfile implements StateProfile { +public class VATTransformationProfile implements TimeSeriesProfile { private final Logger logger = LoggerFactory.getLogger(VATTransformationProfile.class); @@ -83,6 +84,14 @@ public void onStateUpdateFromHandler(State state) { callback.sendUpdate((State) transformState(state)); } + @Override + public void onTimeSeriesFromHandler(TimeSeries timeSeries) { + 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(); String percentage = getVATPercentage();