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.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author Stefan Triller - Initial contribution
*/
@NonNullByDefault
-public class MapTransformationProfile implements StateProfile {
+public class MapTransformationProfile implements TimeSeriesProfile {
public static final ProfileTypeUID PROFILE_TYPE_UID = new ProfileTypeUID(
TransformationService.TRANSFORM_PROFILE_SCOPE, "MAP");
callback.sendUpdate((State) transformState(state));
}
+ @Override
+ public void onTimeSeriesFromHandler(TimeSeries timeSeries) {
+ if (function == null || sourceFormat == null) {
+ logger.warn(
+ "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.",
+ FUNCTION_PARAM, SOURCE_FORMAT_PARAM);
+ callback.sendTimeSeries(timeSeries);
+ return;
+ }
+ 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();
try {