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