]> git.basschouten.com Git - openhab-addons.git/blob
0662cb640bb473aa0c5290eea334289eed0f4950
[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             return new ArtnetBridgeHandler((Bridge) thing);
64         } else if (thingTypeUID.equals(THING_TYPE_LIB485_BRIDGE)) {
65             return new Lib485BridgeHandler((Bridge) thing);
66         } else if (thingTypeUID.equals(THING_TYPE_SACN_BRIDGE)) {
67             return new SacnBridgeHandler((Bridge) thing);
68         } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
69             return new DimmerThingHandler(thing);
70         } else if (thingTypeUID.equals(THING_TYPE_COLOR)) {
71             return new ColorThingHandler(thing);
72         } else if (thingTypeUID.equals(THING_TYPE_TUNABLEWHITE)) {
73             return new TunableWhiteThingHandler(thing);
74         } else if (thingTypeUID.equals(THING_TYPE_CHASER)) {
75             return new ChaserThingHandler(thing);
76         }
77         return null;
78     }
79 }