Implement TimeSeriesProfile (#15873)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2023-11-11 13:30:52 +01:00 committed by GitHub
parent 97039d0a3f
commit 49b952b9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,12 +23,13 @@ import org.openhab.core.library.types.QuantityType;
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 @@ import org.slf4j.LoggerFactory;
* @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 class VATTransformationProfile implements StateProfile {
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();