2 * Copyright (c) 2010-2022 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.DaliRgbHandler;
25 import org.openhab.binding.dali.internal.handler.DaliserverBridgeHandler;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Component;
35 * The {@link DaliHandlerFactory} is responsible for creating things and thing
38 * @author Robert Schmid - Initial contribution
41 @Component(configurationPid = "binding.dali", service = ThingHandlerFactory.class)
42 public class DaliHandlerFactory extends BaseThingHandlerFactory {
44 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
45 .concat(DaliserverBridgeHandler.SUPPORTED_THING_TYPES.stream(),
46 DaliBindingConstants.SUPPORTED_DEVICE_THING_TYPES_UIDS.stream())
47 .collect(Collectors.toSet());
50 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
55 protected @Nullable ThingHandler createHandler(Thing thing) {
56 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
58 if (DaliserverBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
59 return new DaliserverBridgeHandler((Bridge) thing);
61 if (THING_TYPE_DEVICE.equals(thingTypeUID) || THING_TYPE_GROUP.equals(thingTypeUID)) {
62 return new DaliDeviceHandler(thing);
64 if (THING_TYPE_RGB.equals(thingTypeUID)) {
65 return new DaliRgbHandler(thing);