]> git.basschouten.com Git - openhab-addons.git/blob
8daf620ad9e4acac959e7b8154e9bfddf9e7a466
[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.dali.internal;
14
15 import static org.openhab.binding.dali.internal.DaliBindingConstants.*;
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.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;
34
35 /**
36  * The {@link DaliHandlerFactory} is responsible for creating things and thing
37  * handlers.
38  *
39  * @author Robert Schmid - Initial contribution
40  */
41 @NonNullByDefault
42 @Component(configurationPid = "binding.dali", service = ThingHandlerFactory.class)
43 public class DaliHandlerFactory extends BaseThingHandlerFactory {
44
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());
49
50     @Override
51     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
52         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
53     }
54
55     @Override
56     protected @Nullable ThingHandler createHandler(Thing thing) {
57         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
58
59         if (DaliserverBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
60             return new DaliserverBridgeHandler((Bridge) thing);
61         }
62         if (THING_TYPE_DEVICE.equals(thingTypeUID) || THING_TYPE_GROUP.equals(thingTypeUID)) {
63             return new DaliDeviceHandler(thing);
64         }
65         if (THING_TYPE_RGB.equals(thingTypeUID)) {
66             return new DaliRgbHandler(thing);
67         }
68         if (THING_TYPE_DEVICE_DT8.equals(thingTypeUID) || THING_TYPE_GROUP_DT8.equals(thingTypeUID)) {
69             return new DaliDt8DeviceHandler(thing);
70         }
71
72         return null;
73     }
74 }