diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ChannelHandlerFactory.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ChannelHandlerFactory.java new file mode 100644 index 0000000000..ca93bd4988 --- /dev/null +++ b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ChannelHandlerFactory.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2021-2023 Contributors to the SmartHome/J project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.smarthomej.binding.tcpudp.internal; + +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.library.types.DateTimeType; +import org.openhab.core.library.types.PointType; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.binding.generic.ChannelHandler; +import org.openhab.core.thing.binding.generic.ChannelTransformation; +import org.openhab.core.thing.binding.generic.converter.ColorChannelHandler; +import org.openhab.core.thing.binding.generic.converter.DimmerChannelHandler; +import org.openhab.core.thing.binding.generic.converter.FixedValueMappingChannelHandler; +import org.openhab.core.thing.binding.generic.converter.GenericChannelHandler; +import org.openhab.core.thing.binding.generic.converter.ImageChannelHandler; +import org.openhab.core.thing.binding.generic.converter.NumberChannelHandler; +import org.openhab.core.thing.binding.generic.converter.PlayerChannelHandler; +import org.openhab.core.thing.binding.generic.converter.RollershutterChannelHandler; +import org.openhab.core.thing.internal.binding.generic.converter.AbstractTransformingChannelHandler; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.smarthomej.binding.tcpudp.internal.config.TcpUdpChannelConfig; + +/** + * The {@link ChannelHandlerFactory} is a helper class for creating {@link ChannelHandler}s + * + * @author Jan N. Klug - Initial contribution + */ +@NonNullByDefault +public class ChannelHandlerFactory { + private final Logger logger = LoggerFactory.getLogger(ChannelHandlerFactory.class); + + private @Nullable Consumer sendValue; + private BiConsumer updateState; + private BiConsumer postCommand; + + public ChannelHandlerFactory(BiConsumer updateState, BiConsumer postCommand, + @Nullable Consumer sendValue) { + this.updateState = updateState; + this.postCommand = postCommand; + this.sendValue = sendValue; + } + + public void setSendValue(Consumer sendValue) { + this.sendValue = sendValue; + } + + public void setUpdateState(BiConsumer updateState) { + this.updateState = updateState; + } + + public void setPostCommand(BiConsumer postCommand) { + this.postCommand = postCommand; + } + + public Optional create(ChannelUID channelUID, @Nullable String acceptedItemType, + TcpUdpChannelConfig channelConfig) { + if (acceptedItemType == null) { + logger.warn("Cannot determine item-type for channel '{}'", channelUID); + return Optional.empty(); + } + + ChannelHandler channelHandler = null; + switch (acceptedItemType) { + case "Color": + channelHandler = createChannelHandler(ColorChannelHandler::new, channelUID, channelConfig); + break; + case "DateTime": + channelHandler = createGenericChannelHandler(channelUID, channelConfig, DateTimeType::new); + break; + case "Dimmer": + channelHandler = createChannelHandler(DimmerChannelHandler::new, channelUID, channelConfig); + break; + case "Contact": + case "Switch": + channelHandler = createChannelHandler(FixedValueMappingChannelHandler::new, channelUID, channelConfig); + break; + case "Image": + channelHandler = new ImageChannelHandler(state -> updateState.accept(channelUID, state)); + break; + case "Location": + channelHandler = createGenericChannelHandler(channelUID, channelConfig, PointType::new); + break; + case "Number": + channelHandler = createChannelHandler(NumberChannelHandler::new, channelUID, channelConfig); + break; + case "Player": + channelHandler = createChannelHandler(PlayerChannelHandler::new, channelUID, channelConfig); + break; + case "Rollershutter": + channelHandler = createChannelHandler(RollershutterChannelHandler::new, channelUID, channelConfig); + break; + case "String": + channelHandler = createGenericChannelHandler(channelUID, channelConfig, StringType::new); + break; + default: + logger.warn("Unsupported item-type '{}'", acceptedItemType); + } + + return Optional.ofNullable(channelHandler); + } + + private ChannelHandler createChannelHandler(AbstractTransformingChannelHandler.Factory factory, + ChannelUID channelUID, TcpUdpChannelConfig channelConfig) { + return factory.create(state -> updateState.accept(channelUID, state), + command -> postCommand.accept(channelUID, command), sendValue, + new ChannelTransformation(channelConfig.stateTransformation), + new ChannelTransformation(channelConfig.commandTransformation), channelConfig); + } + + private ChannelHandler createGenericChannelHandler(ChannelUID channelUID, TcpUdpChannelConfig channelConfig, + Function toState) { + AbstractTransformingChannelHandler.Factory factory = (state, command, value, stateTrans, commandTrans, + config) -> new GenericChannelHandler(toState, state, command, value, stateTrans, commandTrans, config); + return createChannelHandler(factory, channelUID, channelConfig); + } +} diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandler.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandler.java index 4dc0d5968f..7a8ae953fb 100644 --- a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandler.java +++ b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandler.java @@ -40,6 +40,9 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.thing.binding.generic.ChannelHandler; +import org.openhab.core.thing.binding.generic.ChannelHandlerContent; +import org.openhab.core.thing.binding.generic.ChannelMode; import org.openhab.core.types.Command; import org.openhab.core.types.RefreshType; import org.openhab.core.types.StateDescription; @@ -49,10 +52,6 @@ import org.smarthomej.binding.tcpudp.internal.config.ClientConfiguration; import org.smarthomej.binding.tcpudp.internal.config.TcpUdpChannelConfig; import org.smarthomej.commons.SimpleDynamicStateDescriptionProvider; -import org.smarthomej.commons.itemvalueconverter.ChannelMode; -import org.smarthomej.commons.itemvalueconverter.ContentWrapper; -import org.smarthomej.commons.itemvalueconverter.ItemValueConverter; -import org.smarthomej.commons.transform.ValueTransformationProvider; /** * The {@link ClientThingHandler} is the thing handler for client type things @@ -65,27 +64,25 @@ public class ClientThingHandler extends BaseThingHandler { private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("SHJ-tcpudp"); private final SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider; - private final Map channels = new HashMap<>(); + private final Map channels = new HashMap<>(); private final Map readCommands = new HashMap<>(); - private Function> doSyncRequest = this::doTcpSyncRequest; - private ItemValueConverterFactory itemValueConverterFactory; + private Function> doSyncRequest = this::doTcpSyncRequest; + private final ChannelHandlerFactory channelHandlerFactory; private @Nullable ScheduledFuture refreshJob = null; protected ClientConfiguration config = new ClientConfiguration(); - public ClientThingHandler(Thing thing, ValueTransformationProvider valueTransformationProvider, - SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { + public ClientThingHandler(Thing thing, SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { super(thing); this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider; - itemValueConverterFactory = new ItemValueConverterFactory(valueTransformationProvider, this::updateState, - this::postCommand, null); + channelHandlerFactory = new ChannelHandlerFactory(this::updateState, this::postCommand, null); } @Override public void handleCommand(ChannelUID channelUID, Command command) { - ItemValueConverter itemValueConverter = channels.get(channelUID); + ChannelHandler itemValueConverter = channels.get(channelUID); if (itemValueConverter == null) { logger.warn("Cannot find channel implementation for channel {}.", channelUID); return; @@ -123,11 +120,11 @@ public void initialize() { // set methods depending on thing-type if (config.protocol == ClientConfiguration.Protocol.UDP) { doSyncRequest = this::doUdpSyncRequest; - itemValueConverterFactory.setSendValue(this::doUdpAsyncSend); + channelHandlerFactory.setSendValue(this::doUdpAsyncSend); logger.debug("Configured '{}' for UDP connections.", thing.getUID()); } else if (config.protocol == ClientConfiguration.Protocol.TCP) { doSyncRequest = this::doTcpSyncRequest; - itemValueConverterFactory.setSendValue(this::doTcpAsyncSend); + channelHandlerFactory.setSendValue(this::doTcpAsyncSend); logger.debug("Configured '{}' for TCP connections.", thing.getUID()); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, @@ -171,14 +168,14 @@ public void dispose() { private void refreshChannel(ChannelUID channelUID, String stateContent) { logger.trace("Refreshing '{}' with command '{}'", channelUID, stateContent); - ItemValueConverter itemValueConverter = channels.get(channelUID); + ChannelHandler channelHandler = channels.get(channelUID); - if (itemValueConverter == null) { + if (channelHandler == null) { logger.warn("Failed to refresh '{}': itemValueConverter not found.", channelUID); return; } - doSyncRequest.apply(stateContent).ifPresent(itemValueConverter::process); + doSyncRequest.apply(stateContent).ifPresent(channelHandler::process); } private void createChannel(Channel channel) { @@ -186,7 +183,7 @@ private void createChannel(Channel channel) { TcpUdpChannelConfig channelConfig = channel.getConfiguration().as(TcpUdpChannelConfig.class); String acceptedItemType = channel.getAcceptedItemType(); - itemValueConverterFactory.create(channelUID, acceptedItemType, channelConfig).ifPresent(itemValueConverter -> { + channelHandlerFactory.create(channelUID, acceptedItemType, channelConfig).ifPresent(itemValueConverter -> { if (channelConfig.mode == ChannelMode.READONLY || channelConfig.mode == ChannelMode.READWRITE) { if (channelConfig.stateContent.isEmpty()) { logger.warn( @@ -234,7 +231,7 @@ protected void doTcpAsyncSend(String command) { }); } - protected Optional doTcpSyncRequest(String request) { + protected Optional doTcpSyncRequest(String request) { try (Socket socket = new Socket(config.host, config.port); OutputStream out = socket.getOutputStream(); InputStream in = socket.getInputStream(); @@ -257,7 +254,7 @@ protected Optional doTcpSyncRequest(String request) { outputByteArrayStream.flush(); - ContentWrapper contentWrapper = new ContentWrapper(outputByteArrayStream.toByteArray(), + ChannelHandlerContent contentWrapper = new ChannelHandlerContent(outputByteArrayStream.toByteArray(), Objects.requireNonNullElse(config.encoding, StandardCharsets.UTF_8.name()), null); updateStatus(ThingStatus.ONLINE); @@ -288,7 +285,7 @@ protected void doUdpAsyncSend(String command) { }); } - protected Optional doUdpSyncRequest(String request) { + protected Optional doUdpSyncRequest(String request) { try (DatagramSocket socket = new DatagramSocket()) { socket.setSoTimeout(config.timeout); InetAddress inetAddress = InetAddress.getByName(config.host); @@ -301,8 +298,8 @@ protected Optional doUdpSyncRequest(String request) { packet = new DatagramPacket(receiveBuffer, receiveBuffer.length); socket.receive(packet); - ContentWrapper contentWrapper = new ContentWrapper(Arrays.copyOf(packet.getData(), packet.getLength()), - getEncoding(), null); + ChannelHandlerContent contentWrapper = new ChannelHandlerContent( + Arrays.copyOf(packet.getData(), packet.getLength()), getEncoding(), null); updateStatus(ThingStatus.ONLINE); return Optional.of(contentWrapper); diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ItemValueConverterFactory.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ItemValueConverterFactory.java deleted file mode 100644 index 5aa18270aa..0000000000 --- a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ItemValueConverterFactory.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright (c) 2021-2023 Contributors to the SmartHome/J project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.smarthomej.binding.tcpudp.internal; - -import java.util.Optional; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.library.types.DateTimeType; -import org.openhab.core.library.types.PointType; -import org.openhab.core.library.types.StringType; -import org.openhab.core.thing.ChannelUID; -import org.openhab.core.types.Command; -import org.openhab.core.types.State; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smarthomej.binding.tcpudp.internal.config.TcpUdpChannelConfig; -import org.smarthomej.commons.itemvalueconverter.ItemValueConverter; -import org.smarthomej.commons.itemvalueconverter.converter.AbstractTransformingItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.ColorItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.DimmerItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.FixedValueMappingItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.GenericItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.ImageItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.NumberItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.PlayerItemConverter; -import org.smarthomej.commons.itemvalueconverter.converter.RollershutterItemConverter; -import org.smarthomej.commons.transform.ValueTransformationProvider; - -/** - * The {@link ItemValueConverterFactory} is a helper class for creating {@link ItemValueConverter}s - * - * @author Jan N. Klug - Initial contribution - */ -@NonNullByDefault -public class ItemValueConverterFactory { - private final Logger logger = LoggerFactory.getLogger(ItemValueConverterFactory.class); - - private final ValueTransformationProvider valueTransformationProvider; - - private @Nullable Consumer sendValue; - private BiConsumer updateState; - private BiConsumer postCommand; - - public ItemValueConverterFactory(ValueTransformationProvider valueTransformationProvider, - BiConsumer updateState, BiConsumer postCommand, - @Nullable Consumer sendValue) { - this.valueTransformationProvider = valueTransformationProvider; - this.updateState = updateState; - this.postCommand = postCommand; - this.sendValue = sendValue; - } - - public void setSendValue(Consumer sendValue) { - this.sendValue = sendValue; - } - - public void setUpdateState(BiConsumer updateState) { - this.updateState = updateState; - } - - public void setPostCommand(BiConsumer postCommand) { - this.postCommand = postCommand; - } - - public Optional create(ChannelUID channelUID, @Nullable String acceptedItemType, - TcpUdpChannelConfig channelConfig) { - if (acceptedItemType == null) { - logger.warn("Cannot determine item-type for channel '{}'", channelUID); - return Optional.empty(); - } - - ItemValueConverter itemValueConverter = null; - switch (acceptedItemType) { - case "Color": - itemValueConverter = createItemConverter(ColorItemConverter::new, channelUID, channelConfig); - break; - case "DateTime": - itemValueConverter = createGenericItemConverter(channelUID, channelConfig, DateTimeType::new); - break; - case "Dimmer": - itemValueConverter = createItemConverter(DimmerItemConverter::new, channelUID, channelConfig); - break; - case "Contact": - case "Switch": - itemValueConverter = createItemConverter(FixedValueMappingItemConverter::new, channelUID, - channelConfig); - break; - case "Image": - itemValueConverter = new ImageItemConverter(state -> updateState.accept(channelUID, state)); - break; - case "Location": - itemValueConverter = createGenericItemConverter(channelUID, channelConfig, PointType::new); - break; - case "Number": - itemValueConverter = createItemConverter(NumberItemConverter::new, channelUID, channelConfig); - break; - case "Player": - itemValueConverter = createItemConverter(PlayerItemConverter::new, channelUID, channelConfig); - break; - case "Rollershutter": - itemValueConverter = createItemConverter(RollershutterItemConverter::new, channelUID, channelConfig); - break; - case "String": - itemValueConverter = createGenericItemConverter(channelUID, channelConfig, StringType::new); - break; - default: - logger.warn("Unsupported item-type '{}'", acceptedItemType); - } - - return Optional.ofNullable(itemValueConverter); - } - - private ItemValueConverter createItemConverter(AbstractTransformingItemConverter.Factory factory, - ChannelUID channelUID, TcpUdpChannelConfig channelConfig) { - return factory.create(state -> updateState.accept(channelUID, state), - command -> postCommand.accept(channelUID, command), sendValue, - valueTransformationProvider.getValueTransformation(channelConfig.stateTransformation), - valueTransformationProvider.getValueTransformation(channelConfig.commandTransformation), channelConfig); - } - - private ItemValueConverter createGenericItemConverter(ChannelUID channelUID, TcpUdpChannelConfig channelConfig, - Function toState) { - AbstractTransformingItemConverter.Factory factory = (state, command, value, stateTrans, commandTrans, - config) -> new GenericItemConverter(toState, state, command, value, stateTrans, commandTrans, config); - return createItemConverter(factory, channelUID, channelConfig); - } -} diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ReceiverThingHandler.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ReceiverThingHandler.java index 5b06b35c2f..fa435a50af 100644 --- a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ReceiverThingHandler.java +++ b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/ReceiverThingHandler.java @@ -28,6 +28,8 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.thing.binding.generic.ChannelHandler; +import org.openhab.core.thing.binding.generic.ChannelHandlerContent; import org.openhab.core.types.Command; import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; @@ -39,9 +41,6 @@ import org.smarthomej.binding.tcpudp.internal.receiver.Receiver; import org.smarthomej.binding.tcpudp.internal.receiver.TcpReceiver; import org.smarthomej.binding.tcpudp.internal.receiver.UdpReceiver; -import org.smarthomej.commons.itemvalueconverter.ContentWrapper; -import org.smarthomej.commons.itemvalueconverter.ItemValueConverter; -import org.smarthomej.commons.transform.ValueTransformationProvider; /** * The {@link ReceiverThingHandler} is a teh thing handler for receiver type things @@ -52,7 +51,7 @@ public class ReceiverThingHandler extends BaseThingHandler implements Receiver.ReceiverListener { private final Logger logger = LoggerFactory.getLogger(ReceiverThingHandler.class); - private final ItemValueConverterFactory itemValueConverterFactory; + private final ChannelHandlerFactory itemValueConverterFactory; private final Set contentListeners = new HashSet<>(); private final Map stateCache = new ConcurrentHashMap<>(); @@ -61,11 +60,10 @@ public class ReceiverThingHandler extends BaseThingHandler implements Receiver.R protected ReceiverConfiguration config = new ReceiverConfiguration(); - public ReceiverThingHandler(Thing thing, ValueTransformationProvider valueTransformationProvider) { + public ReceiverThingHandler(Thing thing) { super(thing); - itemValueConverterFactory = new ItemValueConverterFactory(valueTransformationProvider, this::updateState, - this::postCommand, null); + itemValueConverterFactory = new ChannelHandlerFactory(this::updateState, this::postCommand, null); } @Override @@ -146,10 +144,10 @@ private String getEncoding() { @Override public void onReceive(String sender, byte[] content) { - ContentWrapper contentWrapper = new ContentWrapper(content, getEncoding(), null); + ChannelHandlerContent contentWrapper = new ChannelHandlerContent(content, getEncoding(), null); contentListeners.stream().filter(listener -> listener.addressFilter.matcher(sender).matches()) - .forEach(listener -> listener.itemValueConverter.process(contentWrapper)); + .forEach(listener -> listener.channelHandler.process(contentWrapper)); } @Override @@ -162,14 +160,14 @@ public void reportConnectionState(boolean state, @Nullable String message) { } /** - * The {@link ContentListener} is a class that groups an {@link ItemValueConverter} and an associated address filter + * The {@link ContentListener} is a class that groups an {@link ChannelHandler} and an associated address filter */ public static class ContentListener { - public final ItemValueConverter itemValueConverter; + public final ChannelHandler channelHandler; public final Pattern addressFilter; - public ContentListener(ItemValueConverter itemValueConverter, String addressFilter) { - this.itemValueConverter = itemValueConverter; + public ContentListener(ChannelHandler channelHandler, String addressFilter) { + this.channelHandler = channelHandler; // convert input pattern to regex, using only * as wildcard this.addressFilter = Pattern.compile(Pattern.quote(addressFilter).replace("*", "\\E.*?\\Q")); } diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/TcpUdpHandlerFactory.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/TcpUdpHandlerFactory.java index fc3ded0861..1ee5f03118 100644 --- a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/TcpUdpHandlerFactory.java +++ b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/TcpUdpHandlerFactory.java @@ -27,7 +27,6 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.smarthomej.commons.SimpleDynamicStateDescriptionProvider; -import org.smarthomej.commons.transform.ValueTransformationProvider; /** * The {@link TcpUdpHandlerFactory} is responsible for creating things and thing @@ -42,13 +41,10 @@ public class TcpUdpHandlerFactory extends BaseThingHandlerFactory { private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_UID_CLIENT, THING_TYPE_UID_RECEIVER); - private final ValueTransformationProvider valueTransformationProvider; private final SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider; @Activate - public TcpUdpHandlerFactory(@Reference ValueTransformationProvider valueTransformationProvider, - @Reference SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { - this.valueTransformationProvider = valueTransformationProvider; + public TcpUdpHandlerFactory(@Reference SimpleDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider; } @@ -62,9 +58,9 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (THING_TYPE_UID_CLIENT.equals(thingTypeUID)) { - return new ClientThingHandler(thing, valueTransformationProvider, dynamicStateDescriptionProvider); + return new ClientThingHandler(thing, dynamicStateDescriptionProvider); } else if (THING_TYPE_UID_RECEIVER.equals(thingTypeUID)) { - return new ReceiverThingHandler(thing, valueTransformationProvider); + return new ReceiverThingHandler(thing); } return null; diff --git a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/config/TcpUdpChannelConfig.java b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/config/TcpUdpChannelConfig.java index 1f3aa1c90b..d376ecea7c 100644 --- a/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/config/TcpUdpChannelConfig.java +++ b/bundles/org.smarthomej.binding.tcpudp/src/main/java/org/smarthomej/binding/tcpudp/internal/config/TcpUdpChannelConfig.java @@ -14,7 +14,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.smarthomej.commons.itemvalueconverter.ItemValueConverterChannelConfig; +import org.openhab.core.thing.binding.generic.ChannelValueConverterConfig; /** * The {@link TcpUdpChannelConfig} class contains fields mapping channel configuration parameters. @@ -22,7 +22,7 @@ * @author Jan N. Klug - Initial contribution */ @NonNullByDefault -public class TcpUdpChannelConfig extends ItemValueConverterChannelConfig { +public class TcpUdpChannelConfig extends ChannelValueConverterConfig { public @Nullable String stateTransformation; diff --git a/bundles/org.smarthomej.binding.tcpudp/src/test/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandlerTest.java b/bundles/org.smarthomej.binding.tcpudp/src/test/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandlerTest.java index 5f20d7ae9b..59e65da24b 100644 --- a/bundles/org.smarthomej.binding.tcpudp/src/test/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandlerTest.java +++ b/bundles/org.smarthomej.binding.tcpudp/src/test/java/org/smarthomej/binding/tcpudp/internal/ClientThingHandlerTest.java @@ -46,13 +46,13 @@ import org.openhab.core.thing.binding.ThingHandlerCallback; import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; +import org.openhab.core.thing.binding.generic.ChannelMode; import org.openhab.core.thing.type.ChannelTypeUID; import org.smarthomej.binding.tcpudp.internal.config.ClientConfiguration; import org.smarthomej.binding.tcpudp.internal.config.TcpUdpChannelConfig; import org.smarthomej.binding.tcpudp.internal.test.EchoServer; import org.smarthomej.binding.tcpudp.internal.test.TestUtil; import org.smarthomej.commons.SimpleDynamicStateDescriptionProvider; -import org.smarthomej.commons.itemvalueconverter.ChannelMode; import org.smarthomej.commons.transform.NoOpValueTransformation; import org.smarthomej.commons.transform.ValueTransformationProvider; @@ -183,7 +183,7 @@ private ClientThingHandler getClientThingHandler(ClientConfiguration clientConfi .withConfiguration(TestUtil.getConfigurationFromInstance(clientConfiguration)).withChannel(channel) .build(); - ClientThingHandler testClientThingHandler = new ClientThingHandler(thing, valueTransformationProvider, + ClientThingHandler testClientThingHandler = new ClientThingHandler(thing, simpleDynamicStateDescriptionProvider); testClientThingHandler.setCallback(thingHandlerCallback);