Skip to content

Commit 376b696

Browse files
authored
add timeseries support (openhab#17334)
Signed-off-by: Hans Böhm <h.boehm@gmx.at>
1 parent f5eb2c6 commit 376b696

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

bundles/org.openhab.transform.map/src/main/java/org/openhab/transform/map/internal/profiles/MapTransformationProfile.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
import org.openhab.core.thing.profiles.ProfileCallback;
1818
import org.openhab.core.thing.profiles.ProfileContext;
1919
import org.openhab.core.thing.profiles.ProfileTypeUID;
20-
import org.openhab.core.thing.profiles.StateProfile;
20+
import org.openhab.core.thing.profiles.TimeSeriesProfile;
2121
import org.openhab.core.transform.TransformationException;
2222
import org.openhab.core.transform.TransformationHelper;
2323
import org.openhab.core.transform.TransformationService;
2424
import org.openhab.core.types.Command;
2525
import org.openhab.core.types.State;
26+
import org.openhab.core.types.TimeSeries;
2627
import org.openhab.core.types.Type;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
@@ -33,7 +34,7 @@
3334
* @author Stefan Triller - Initial contribution
3435
*/
3536
@NonNullByDefault
36-
public class MapTransformationProfile implements StateProfile {
37+
public class MapTransformationProfile implements TimeSeriesProfile {
3738

3839
public static final ProfileTypeUID PROFILE_TYPE_UID = new ProfileTypeUID(
3940
TransformationService.TRANSFORM_PROFILE_SCOPE, "MAP");
@@ -113,6 +114,21 @@ public void onStateUpdateFromHandler(State state) {
113114
callback.sendUpdate((State) transformState(state));
114115
}
115116

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+
116132
private Type transformState(Type state) {
117133
String result = state.toFullString();
118134
try {

0 commit comments

Comments
 (0)