]> git.basschouten.com Git - openhab-addons.git/blob
7598e2a491bc0d07c15aa68f65cddb845abdd4f2
[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.openwebnet.internal;
14
15 import static org.openhab.binding.openwebnet.OpenWebNetBindingConstants.ALL_SUPPORTED_THING_TYPES;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.openwebnet.handler.OpenWebNetAutomationHandler;
20 import org.openhab.binding.openwebnet.handler.OpenWebNetBridgeHandler;
21 import org.openhab.binding.openwebnet.handler.OpenWebNetGenericHandler;
22 import org.openhab.binding.openwebnet.handler.OpenWebNetLightingHandler;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * The {@link OpenWebNetHandlerFactory} is responsible for creating thing handlers.
35  *
36  * @author Massimo Valla - Initial contribution
37  */
38 @NonNullByDefault
39 @Component(configurationPid = "binding.openwebnet", service = ThingHandlerFactory.class)
40 public class OpenWebNetHandlerFactory extends BaseThingHandlerFactory {
41
42     private final Logger logger = LoggerFactory.getLogger(OpenWebNetHandlerFactory.class);
43
44     @Override
45     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
46         return ALL_SUPPORTED_THING_TYPES.contains(thingTypeUID);
47     }
48
49     @Override
50     protected @Nullable ThingHandler createHandler(Thing thing) {
51         if (OpenWebNetBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
52             logger.debug("creating NEW BRIDGE Handler");
53             return new OpenWebNetBridgeHandler((Bridge) thing);
54         } else if (OpenWebNetGenericHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
55             logger.debug("creating NEW GENERIC Handler");
56             return new OpenWebNetGenericHandler(thing);
57         } else if (OpenWebNetLightingHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
58             logger.debug("creating NEW LIGHTING Handler");
59             return new OpenWebNetLightingHandler(thing);
60         } else if (OpenWebNetAutomationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
61             logger.debug("creating NEW AUTOMATION Handler");
62             return new OpenWebNetAutomationHandler(thing);
63         }
64         logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());
65         return null;
66     }
67 }