2 * Copyright (c) 2010-2024 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.OpenWebNetAlarmHandler;
20 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAutomationHandler;
21 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetAuxiliaryHandler;
22 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetBridgeHandler;
23 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetEnergyHandler;
24 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetGenericHandler;
25 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetLightingHandler;
26 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetScenarioBasicHandler;
27 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetScenarioHandler;
28 import org.openhab.binding.openwebnet.internal.handler.OpenWebNetThermoregulationHandler;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
33 import org.openhab.core.thing.binding.ThingHandler;
34 import org.openhab.core.thing.binding.ThingHandlerFactory;
35 import org.osgi.service.component.annotations.Component;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * The {@link OpenWebNetHandlerFactory} is responsible for creating thing handlers.
42 * @author Massimo Valla - Initial contribution, updates
43 * @author Andrea Conte - Energy management, Thermoregulation
44 * @author Gilberto Cocchi - Thermoregulation
45 * @author Giovanni Fabiani - Auxiliary support
48 @Component(configurationPid = "binding.openwebnet", service = ThingHandlerFactory.class)
49 public class OpenWebNetHandlerFactory extends BaseThingHandlerFactory {
51 private final Logger logger = LoggerFactory.getLogger(OpenWebNetHandlerFactory.class);
54 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55 return ALL_SUPPORTED_THING_TYPES.contains(thingTypeUID);
59 protected @Nullable ThingHandler createHandler(Thing thing) {
60 if (OpenWebNetBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
61 logger.debug("creating NEW BRIDGE Handler --- {}", thing.getUID());
62 return new OpenWebNetBridgeHandler((Bridge) thing);
63 } else if (OpenWebNetGenericHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
64 logger.debug("creating NEW GENERIC Handler --- {}", thing.getUID());
65 return new OpenWebNetGenericHandler(thing);
66 } else if (OpenWebNetLightingHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
67 logger.debug("creating NEW LIGHTING Handler --- {}", thing.getUID());
68 return new OpenWebNetLightingHandler(thing);
69 } else if (OpenWebNetAutomationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
70 logger.debug("creating NEW AUTOMATION Handler --- {}", thing.getUID());
71 return new OpenWebNetAutomationHandler(thing);
72 } else if (OpenWebNetEnergyHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
73 logger.debug("creating NEW ENERGY Handler --- {}", thing.getUID());
74 return new OpenWebNetEnergyHandler(thing);
75 } else if (OpenWebNetThermoregulationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
76 logger.debug("creating NEW THERMO Handler --- {}", thing.getUID());
77 return new OpenWebNetThermoregulationHandler(thing);
78 } else if (OpenWebNetScenarioHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
79 logger.debug("creating NEW SCENARIO Handler --- {}", thing.getUID());
80 return new OpenWebNetScenarioHandler(thing);
81 } else if (OpenWebNetAuxiliaryHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
82 logger.debug("Creating NEW AUXILIARY Handler");
83 return new OpenWebNetAuxiliaryHandler(thing);
84 } else if (OpenWebNetScenarioBasicHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
85 logger.debug("Creating NEW BASIC SCENARIO Handler");
86 return new OpenWebNetScenarioBasicHandler(thing);
87 } else if (OpenWebNetAlarmHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
88 logger.debug("creating NEW ALARM Handler");
89 return new OpenWebNetAlarmHandler(thing);
91 logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());