|
17 | 17 | import org.openhab.core.thing.profiles.ProfileCallback;
|
18 | 18 | import org.openhab.core.thing.profiles.ProfileContext;
|
19 | 19 | import org.openhab.core.thing.profiles.ProfileTypeUID;
|
20 |
| -import org.openhab.core.thing.profiles.StateProfile; |
| 20 | +import org.openhab.core.thing.profiles.TimeSeriesProfile; |
21 | 21 | import org.openhab.core.transform.TransformationException;
|
22 | 22 | import org.openhab.core.transform.TransformationHelper;
|
23 | 23 | import org.openhab.core.transform.TransformationService;
|
24 | 24 | import org.openhab.core.types.Command;
|
25 | 25 | import org.openhab.core.types.State;
|
| 26 | +import org.openhab.core.types.TimeSeries; |
26 | 27 | import org.openhab.core.types.Type;
|
27 | 28 | import org.slf4j.Logger;
|
28 | 29 | import org.slf4j.LoggerFactory;
|
|
33 | 34 | * @author Stefan Triller - Initial contribution
|
34 | 35 | */
|
35 | 36 | @NonNullByDefault
|
36 |
| -public class MapTransformationProfile implements StateProfile { |
| 37 | +public class MapTransformationProfile implements TimeSeriesProfile { |
37 | 38 |
|
38 | 39 | public static final ProfileTypeUID PROFILE_TYPE_UID = new ProfileTypeUID(
|
39 | 40 | TransformationService.TRANSFORM_PROFILE_SCOPE, "MAP");
|
@@ -113,6 +114,21 @@ public void onStateUpdateFromHandler(State state) {
|
113 | 114 | callback.sendUpdate((State) transformState(state));
|
114 | 115 | }
|
115 | 116 |
|
| 117 | + @Override |
| 118 | + public void onTimeSeriesFromHandler(TimeSeries timeSeries) { |
| 119 | + if (function == null || sourceFormat == null) { |
| 120 | + logger.warn( |
| 121 | + "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.", |
| 122 | + FUNCTION_PARAM, SOURCE_FORMAT_PARAM); |
| 123 | + callback.sendTimeSeries(timeSeries); |
| 124 | + return; |
| 125 | + } |
| 126 | + TimeSeries transformedTimeSeries = new TimeSeries(timeSeries.getPolicy()); |
| 127 | + timeSeries.getStates() |
| 128 | + .forEach(entry -> transformedTimeSeries.add(entry.timestamp(), (State) transformState(entry.state()))); |
| 129 | + callback.sendTimeSeries(transformedTimeSeries); |
| 130 | + } |
| 131 | + |
116 | 132 | private Type transformState(Type state) {
|
117 | 133 | String result = state.toFullString();
|
118 | 134 | try {
|
|
0 commit comments