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