]> git.basschouten.com Git - openhab-addons.git/blob
e90b8cef98897fc4392b981ab17ac2f68e9bd422
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.serial.internal.channel;
14
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;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.serial.internal.transform.ValueTransformationProvider;
24
25 /**
26  * A factory to create {@link DeviceChannel} objects
27  *
28  * @author Mike Major - Initial contribution
29  */
30 @NonNullByDefault
31 public class DeviceChannelFactory {
32
33     /**
34      * Create a {@link DeviceChannel} for the channel type
35      * 
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.
40      */
41     public static @Nullable DeviceChannel createDeviceChannel(
42             final ValueTransformationProvider valueTransformationProvider, final ChannelConfig channelConfig,
43             final String channelTypeID) {
44         DeviceChannel deviceChannel;
45
46         switch (channelTypeID) {
47             case DEVICE_STRING_CHANNEL:
48                 deviceChannel = new StringChannel(valueTransformationProvider, channelConfig);
49                 break;
50             case DEVICE_NUMBER_CHANNEL:
51                 deviceChannel = new NumberChannel(valueTransformationProvider, channelConfig);
52                 break;
53             case DEVICE_DIMMER_CHANNEL:
54                 deviceChannel = new DimmerChannel(valueTransformationProvider, channelConfig);
55                 break;
56             case DEVICE_SWITCH_CHANNEL:
57                 deviceChannel = new SwitchChannel(valueTransformationProvider, channelConfig);
58                 break;
59             case DEVICE_ROLLERSHUTTER_CHANNEL:
60                 deviceChannel = new RollershutterChannel(valueTransformationProvider, channelConfig);
61                 break;
62             default:
63                 deviceChannel = null;
64                 break;
65         }
66
67         return deviceChannel;
68     }
69 }