]> git.basschouten.com Git - openhab-addons.git/blob
2b8f258d83cf30cfe5e65a2a788774e32dd2c3cb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.dmx.internal;
14
15 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
16
17 import java.util.Set;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.dmx.internal.handler.ArtnetBridgeHandler;
24 import org.openhab.binding.dmx.internal.handler.ChaserThingHandler;
25 import org.openhab.binding.dmx.internal.handler.ColorThingHandler;
26 import org.openhab.binding.dmx.internal.handler.DimmerThingHandler;
27 import org.openhab.binding.dmx.internal.handler.Lib485BridgeHandler;
28 import org.openhab.binding.dmx.internal.handler.SacnBridgeHandler;
29 import org.openhab.binding.dmx.internal.handler.TunableWhiteThingHandler;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
34 import org.openhab.core.thing.binding.ThingHandler;
35 import org.openhab.core.thing.binding.ThingHandlerFactory;
36 import org.osgi.service.component.annotations.Component;
37
38 /**
39  * The {@link DmxHandlerFactory} is responsible for creating things and thing
40  * handlers.
41  *
42  * @author Jan N. Klug - Initial contribution
43  */
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.dmx")
45 @NonNullByDefault
46 public class DmxHandlerFactory extends BaseThingHandlerFactory {
47     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
48             .of(ArtnetBridgeHandler.SUPPORTED_THING_TYPES, Lib485BridgeHandler.SUPPORTED_THING_TYPES,
49                     SacnBridgeHandler.SUPPORTED_THING_TYPES, ChaserThingHandler.SUPPORTED_THING_TYPES,
50                     ColorThingHandler.SUPPORTED_THING_TYPES, DimmerThingHandler.SUPPORTED_THING_TYPES,
51                     TunableWhiteThingHandler.SUPPORTED_THING_TYPES)
52             .flatMap(Set::stream).collect(Collectors.toUnmodifiableSet());
53
54     @Override
55     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
56         return SUPPORTED_THING_TYPES.contains(thingTypeUID);
57     }
58
59     @Override
60     protected @Nullable ThingHandler createHandler(Thing thing) {
61         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
62         if (thingTypeUID.equals(THING_TYPE_ARTNET_BRIDGE)) {
63             ArtnetBridgeHandler handler = new ArtnetBridgeHandler((Bridge) thing);
64             return handler;
65         } else if (thingTypeUID.equals(THING_TYPE_LIB485_BRIDGE)) {
66             Lib485BridgeHandler handler = new Lib485BridgeHandler((Bridge) thing);
67             return handler;
68         } else if (thingTypeUID.equals(THING_TYPE_SACN_BRIDGE)) {
69             SacnBridgeHandler handler = new SacnBridgeHandler((Bridge) thing);
70             return handler;
71         } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
72             DimmerThingHandler handler = new DimmerThingHandler(thing);
73             return handler;
74         } else if (thingTypeUID.equals(THING_TYPE_COLOR)) {
75             ColorThingHandler handler = new ColorThingHandler(thing);
76             return handler;
77         } else if (thingTypeUID.equals(THING_TYPE_TUNABLEWHITE)) {
78             TunableWhiteThingHandler handler = new TunableWhiteThingHandler(thing);
79             return handler;
80         } else if (thingTypeUID.equals(THING_TYPE_CHASER)) {
81             ChaserThingHandler handler = new ChaserThingHandler(thing);
82             return handler;
83         }
84         return null;
85     }
86 }