Skip to content

Commit

Permalink
Implement TimeSeriesProfile (openhab#15873)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
  • Loading branch information
jlaur authored and austvik committed Mar 27, 2024
1 parent 25c5527 commit 09b32a9
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 09b32a9

Please sign in to comment.