2 * Copyright (c) 2010-2021 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.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.handler.OpenWebNetAutomationHandler;
20 import org.openhab.binding.openwebnet.handler.OpenWebNetBridgeHandler;
21 import org.openhab.binding.openwebnet.handler.OpenWebNetEnergyHandler;
22 import org.openhab.binding.openwebnet.handler.OpenWebNetGenericHandler;
23 import org.openhab.binding.openwebnet.handler.OpenWebNetLightingHandler;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Component;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The {@link OpenWebNetHandlerFactory} is responsible for creating thing handlers.
37 * @author Massimo Valla - Initial contribution
38 * @author Andrea Conte - Energy management
41 @Component(configurationPid = "binding.openwebnet", service = ThingHandlerFactory.class)
42 public class OpenWebNetHandlerFactory extends BaseThingHandlerFactory {
44 private final Logger logger = LoggerFactory.getLogger(OpenWebNetHandlerFactory.class);
47 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
48 return ALL_SUPPORTED_THING_TYPES.contains(thingTypeUID);
52 protected @Nullable ThingHandler createHandler(Thing thing) {
53 if (OpenWebNetBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
54 logger.debug("creating NEW BRIDGE Handler");
55 return new OpenWebNetBridgeHandler((Bridge) thing);
56 } else if (OpenWebNetGenericHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
57 logger.debug("creating NEW GENERIC Handler");
58 return new OpenWebNetGenericHandler(thing);
59 } else if (OpenWebNetLightingHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
60 logger.debug("creating NEW LIGHTING Handler");
61 return new OpenWebNetLightingHandler(thing);
62 } else if (OpenWebNetAutomationHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
63 logger.debug("creating NEW AUTOMATION Handler");
64 return new OpenWebNetAutomationHandler(thing);
65 } else if (OpenWebNetEnergyHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
66 logger.debug("creating NEW ENERGY Handler");
67 return new OpenWebNetEnergyHandler(thing);
69 logger.warn("ThingType {} is not supported by this binding", thing.getThingTypeUID());