Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[transform.vat] Add support for time series #15873

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand Down