Search in sources :

Example 1 with TransformationServiceProvider

use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.TransformationServiceProvider in project smarthome by eclipse.

the class GenericThingHandler method createChannelState.

/**
 * For every Thing channel there exists a corresponding {@link ChannelState}. It consists of the MQTT state
 * and MQTT command topic, the ChannelUID and a value state.
 *
 * @param channelConfig The channel configuration that contains MQTT state and command topic and multiple other
 *            configurations.
 * @param channelUID The channel UID
 * @param valueState The channel value state
 * @return
 */
protected ChannelState createChannelState(ChannelConfig channelConfig, ChannelUID channelUID, Value valueState) {
    ChannelState state = new ChannelState(channelConfig, channelUID, valueState, this);
    String[] transformations;
    // Incoming value transformations
    transformations = channelConfig.transformationPattern.split("∩");
    Stream.of(transformations).filter(t -> StringUtils.isNotBlank(t)).map(t -> new ChannelStateTransformation(t, transformationServiceProvider)).forEach(t -> state.addTransformation(t));
    // Outgoing value transformations
    transformations = channelConfig.transformationPatternOut.split("∩");
    Stream.of(transformations).filter(t -> StringUtils.isNotBlank(t)).map(t -> new ChannelStateTransformation(t, transformationServiceProvider)).forEach(t -> state.addTransformationOut(t));
    return state;
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) StringUtils(org.apache.commons.lang.StringUtils) MqttChannelStateDescriptionProvider(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.MqttChannelStateDescriptionProvider) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ChannelState(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState) TransformationServiceProvider(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.TransformationServiceProvider) ChannelConfig(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelConfig) ArrayList(java.util.ArrayList) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) ChannelStateUpdateListener(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateUpdateListener) Value(org.eclipse.smarthome.binding.mqtt.generic.internal.values.Value) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) ValueFactory(org.eclipse.smarthome.binding.mqtt.generic.internal.values.ValueFactory) MqttBrokerConnection(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection) ChannelStateTransformation(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateTransformation) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Stream(java.util.stream.Stream) ThingStatusDetail(org.eclipse.smarthome.core.thing.ThingStatusDetail) StateDescription(org.eclipse.smarthome.core.types.StateDescription) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) ChannelStateTransformation(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateTransformation) ChannelState(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang.StringUtils)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 ChannelConfig (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelConfig)1 ChannelState (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState)1 ChannelStateTransformation (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateTransformation)1 ChannelStateUpdateListener (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelStateUpdateListener)1 MqttChannelStateDescriptionProvider (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.MqttChannelStateDescriptionProvider)1 TransformationServiceProvider (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.TransformationServiceProvider)1 Value (org.eclipse.smarthome.binding.mqtt.generic.internal.values.Value)1