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.dali.internal;
15 import static org.openhab.binding.dali.internal.DaliBindingConstants.*;
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.dali.internal.handler.DaliDeviceHandler;
24 import org.openhab.binding.dali.internal.handler.DaliDt8DeviceHandler;
25 import org.openhab.binding.dali.internal.handler.DaliRgbHandler;
26 import org.openhab.binding.dali.internal.handler.DaliserverBridgeHandler;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Component;
36 * The {@link DaliHandlerFactory} is responsible for creating things and thing
39 * @author Robert Schmid - Initial contribution
42 @Component(configurationPid = "binding.dali", service = ThingHandlerFactory.class)
43 public class DaliHandlerFactory extends BaseThingHandlerFactory {
45 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
46 .concat(DaliserverBridgeHandler.SUPPORTED_THING_TYPES.stream(),
47 DaliBindingConstants.SUPPORTED_DEVICE_THING_TYPES_UIDS.stream())
48 .collect(Collectors.toSet());
51 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
52 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
56 protected @Nullable ThingHandler createHandler(Thing thing) {
57 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
59 if (DaliserverBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
60 return new DaliserverBridgeHandler((Bridge) thing);
62 if (THING_TYPE_DEVICE.equals(thingTypeUID) || THING_TYPE_GROUP.equals(thingTypeUID)) {
63 return new DaliDeviceHandler(thing);
65 if (THING_TYPE_RGB.equals(thingTypeUID)) {
66 return new DaliRgbHandler(thing);
68 if (THING_TYPE_DEVICE_DT8.equals(thingTypeUID) || THING_TYPE_GROUP_DT8.equals(thingTypeUID)) {
69 return new DaliDt8DeviceHandler(thing);