]> git.basschouten.com Git - openhab-addons.git/blob
d3ea931dd70f57924a0b2f4822dab900c0a85954
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.cm11a.internal;
14
15 import static org.openhab.binding.cm11a.internal.CM11ABindingConstants.*;
16
17 import java.util.Set;
18
19 import org.openhab.binding.cm11a.internal.handler.Cm11aApplianceHandler;
20 import org.openhab.binding.cm11a.internal.handler.Cm11aBridgeHandler;
21 import org.openhab.binding.cm11a.internal.handler.Cm11aLampHandler;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.ThingHandlerFactory;
28 import org.osgi.service.component.annotations.Component;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * The {@link Cm11aHandlerFactory} is responsible for creating things and thing
34  * handlers.
35  *
36  * @author Bob Raker - Initial contribution
37  */
38 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.cm11a")
39 public class Cm11aHandlerFactory extends BaseThingHandlerFactory {
40
41     private final Logger logger = LoggerFactory.getLogger(Cm11aHandlerFactory.class);
42
43     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SWITCH, THING_TYPE_DIMMER);
44
45     @Override
46     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
47         return THING_TYPE_CM11A.equals(thingTypeUID) || SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
48     }
49
50     @Override
51     protected ThingHandler createHandler(Thing thing) {
52         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
53         logger.trace("**** Cm11AHandlerFactory.createHandler for {}", thingTypeUID.getAsString());
54
55         if (thingTypeUID.equals(THING_TYPE_CM11A)) {
56             return new Cm11aBridgeHandler((Bridge) thing);
57         } else if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
58             return new Cm11aApplianceHandler(thing);
59         } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
60             return new Cm11aLampHandler(thing);
61         }
62
63         return null;
64     }
65 }