2 * Copyright (c) 2010-2023 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.dmx.internal;
15 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
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;
39 * The {@link DmxHandlerFactory} is responsible for creating things and thing
42 * @author Jan N. Klug - Initial contribution
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.dmx")
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());
55 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
56 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
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);