2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.serial.internal.channel;
15 import static org.openhab.binding.serial.internal.SerialBindingConstants.DEVICE_DIMMER_CHANNEL;
16 import static org.openhab.binding.serial.internal.SerialBindingConstants.DEVICE_NUMBER_CHANNEL;
17 import static org.openhab.binding.serial.internal.SerialBindingConstants.DEVICE_ROLLERSHUTTER_CHANNEL;
18 import static org.openhab.binding.serial.internal.SerialBindingConstants.DEVICE_STRING_CHANNEL;
19 import static org.openhab.binding.serial.internal.SerialBindingConstants.DEVICE_SWITCH_CHANNEL;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.serial.internal.transform.ValueTransformationProvider;
26 * A factory to create {@link DeviceChannel} objects
28 * @author Mike Major - Initial contribution
31 public class DeviceChannelFactory {
34 * Create a {@link DeviceChannel} for the channel type
36 * @param valueTransformationProvider the transformation provider
37 * @param channelConfig the channel configuration
38 * @param channelTypeID the channel type id
39 * @return the DeviceChannel or null if the channel type is not supported.
41 public static @Nullable DeviceChannel createDeviceChannel(
42 final ValueTransformationProvider valueTransformationProvider, final ChannelConfig channelConfig,
43 final String channelTypeID) {
44 DeviceChannel deviceChannel;
46 switch (channelTypeID) {
47 case DEVICE_STRING_CHANNEL:
48 deviceChannel = new StringChannel(valueTransformationProvider, channelConfig);
50 case DEVICE_NUMBER_CHANNEL:
51 deviceChannel = new NumberChannel(valueTransformationProvider, channelConfig);
53 case DEVICE_DIMMER_CHANNEL:
54 deviceChannel = new DimmerChannel(valueTransformationProvider, channelConfig);
56 case DEVICE_SWITCH_CHANNEL:
57 deviceChannel = new SwitchChannel(valueTransformationProvider, channelConfig);
59 case DEVICE_ROLLERSHUTTER_CHANNEL:
60 deviceChannel = new RollershutterChannel(valueTransformationProvider, channelConfig);