2 * Copyright (c) 2010-2023 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.adorne.internal.handler;
15 import static org.openhab.binding.adorne.internal.AdorneBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
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 AdorneHandlerFactory} is responsible for creating thing handlers.
37 * @author Mark Theiding - Initial contribution
40 @Component(configurationPid = "binding.adorne", service = ThingHandlerFactory.class)
41 public class AdorneHandlerFactory extends BaseThingHandlerFactory {
42 private final Logger logger = LoggerFactory.getLogger(AdorneHandlerFactory.class);
43 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
44 Stream.of(THING_TYPE_HUB, THING_TYPE_SWITCH, THING_TYPE_DIMMER).collect(Collectors.toSet()));
47 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
48 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
52 * Creates handlers for switches, dimmers and hubs.
55 protected @Nullable ThingHandler createHandler(Thing thing) {
56 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
58 if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
59 logger.debug("Creating an AdorneSwitchHandler for thing '{}'", thing.getUID());
61 return new AdorneSwitchHandler(thing);
62 } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
63 logger.debug("Creating an AdorneDimmerHandler for thing '{}'", thing.getUID());
65 return new AdorneDimmerHandler(thing);
66 } else if (thingTypeUID.equals(THING_TYPE_HUB)) {
67 logger.debug("Creating an AdorneHubHandler for bridge '{}'", thing.getUID());
69 return new AdorneHubHandler((Bridge) thing);