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