2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.openwebnet.internal;
15 import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.ALL_SUPPORTED_THING_TYPES;
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.OpenWebNetAuxiliaryHandler;
21 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetBridgeHandler;
22 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetEnergyHandler;
23 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetGenericHandler;
24 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetLightingHandler;
25 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetScenarioHandler;
26 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetThermoregulationHandler;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Component;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * The {@link OpenWebNetHandlerFactory} is responsible for creating thing handlers.
40 * @author Massimo Valla - Initial contribution
41 * @author Andrea Conte - Energy management, Thermoregulation
42 * @author Gilberto Cocchi - Thermoregulation
43 * @author Giovanni Fabiani - Auxiliary support
46 @Component(configurationPid = "binding.openwebnet", service = ThingHandlerFactory.class)
47 public class OpenWebNetHandlerFactory extends BaseThingHandlerFactory {
49 private final Logger logger = LoggerFactory.getLogger(OpenWebNetHandlerFactory.class);
52 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
53 return ALL_SUPPORTED_THING_TYPES.contains(thingTypeUID);
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 if (OpenWebNetBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
59 logger.debug("creating NEW BRIDGE Handler --- {}", thing.getUID());
60 return new OpenWebNetBridgeHandler((Bridge) thing);
61 } else if (OpenWebNetGenericHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
62 logger.debug("creating NEW GENERIC Handler --- {}", thing.getUID());
63 return new OpenWebNetGenericHandler(thing);
64 } else if (OpenWebNetLightingHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
65 logger.debug("creating NEW LIGHTING Handler --- {}", thing.getUID());
66 return new OpenWebNetLightingHandler(thing);
67 } else if (OpenWebNetAutomationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
68 logger.debug("creating NEW AUTOMATION Handler --- {}", thing.getUID());
69 return new OpenWebNetAutomationHandler(thing);
70 } else if (OpenWebNetEnergyHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
71 logger.debug("creating NEW ENERGY Handler --- {}", thing.getUID());
72 return new OpenWebNetEnergyHandler(thing);
73 } else if (OpenWebNetThermoregulationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
74 logger.debug("creating NEW THERMO Handler --- {}", thing.getUID());
75 return new OpenWebNetThermoregulationHandler(thing);
76 } else if (OpenWebNetScenarioHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
77 logger.debug("creating NEW SCENARIO Handler --- {}", thing.getUID());
78 return new OpenWebNetScenarioHandler(thing);
79 } else if (OpenWebNetAuxiliaryHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
80 logger.debug("Creating NEW AUXILIARY Handler");
81 return new OpenWebNetAuxiliaryHandler(thing);
83 logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());