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.cm11a.internal;
15 import static org.openhab.binding.cm11a.internal.CM11ABindingConstants.*;
17 import java.util.Arrays;
18 import java.util.Collections;
19 import java.util.HashSet;
22 import org.openhab.binding.cm11a.internal.handler.Cm11aApplianceHandler;
23 import org.openhab.binding.cm11a.internal.handler.Cm11aBridgeHandler;
24 import org.openhab.binding.cm11a.internal.handler.Cm11aLampHandler;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Component;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * The {@link Cm11aHandlerFactory} is responsible for creating things and thing
39 * @author Bob Raker - Initial contribution
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.cm11a")
42 public class Cm11aHandlerFactory extends BaseThingHandlerFactory {
44 private final Logger logger = LoggerFactory.getLogger(Cm11aHandlerFactory.class);
46 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
47 .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_SWITCH, THING_TYPE_DIMMER)));
50 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51 return THING_TYPE_CM11A.equals(thingTypeUID) || SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
55 protected ThingHandler createHandler(Thing thing) {
56 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
57 logger.trace("**** Cm11AHandlerFactory.createHandler for {}", thingTypeUID.getAsString());
59 if (thingTypeUID.equals(THING_TYPE_CM11A)) {
60 return new Cm11aBridgeHandler((Bridge) thing);
61 } else if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
62 return new Cm11aApplianceHandler(thing);
63 } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
64 return new Cm11aLampHandler(thing);