]> git.basschouten.com Git - openhab-addons.git/blob
426d5a4eaf5c7dbe71e13bd4db5153508ea0c9f9
[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.adorne.internal.handler;
14
15 import static org.openhab.binding.adorne.internal.AdorneBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Component;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * The {@link AdorneHandlerFactory} is responsible for creating thing handlers.
36  *
37  * @author Mark Theiding - Initial contribution
38  */
39 @NonNullByDefault
40 @Component(configurationPid = "binding.adorne", service = ThingHandlerFactory.class)
41 public class AdorneHandlerFactory extends BaseThingHandlerFactory {
42     private final Logger logger = LoggerFactory.getLogger(AdorneHandlerFactory.class);
43     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
44             Stream.of(THING_TYPE_HUB, THING_TYPE_SWITCH, THING_TYPE_DIMMER).collect(Collectors.toSet()));
45
46     @Override
47     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
48         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
49     }
50
51     /**
52      * Creates handlers for switches, dimmers and hubs.
53      */
54     @Override
55     protected @Nullable ThingHandler createHandler(Thing thing) {
56         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
57
58         if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
59             logger.debug("Creating an AdorneSwitchHandler for thing '{}'", thing.getUID());
60
61             return new AdorneSwitchHandler(thing);
62         } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
63             logger.debug("Creating an AdorneDimmerHandler for thing '{}'", thing.getUID());
64
65             return new AdorneDimmerHandler(thing);
66         } else if (thingTypeUID.equals(THING_TYPE_HUB)) {
67             logger.debug("Creating an AdorneHubHandler for bridge '{}'", thing.getUID());
68
69             return new AdorneHubHandler((Bridge) thing);
70         }
71
72         return null;
73     }
74 }