]> git.basschouten.com Git - openhab-addons.git/blob
3860827e9d238cf38dd28f3dc119d73fc74dd95e
[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.Arrays;
18 import java.util.Collections;
19 import java.util.HashSet;
20 import java.util.Set;
21
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;
34
35 /**
36  * The {@link Cm11aHandlerFactory} is responsible for creating things and thing
37  * handlers.
38  *
39  * @author Bob Raker - Initial contribution
40  */
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.cm11a")
42 public class Cm11aHandlerFactory extends BaseThingHandlerFactory {
43
44     private final Logger logger = LoggerFactory.getLogger(Cm11aHandlerFactory.class);
45
46     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
47             .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_SWITCH, THING_TYPE_DIMMER)));
48
49     @Override
50     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51         return THING_TYPE_CM11A.equals(thingTypeUID) || SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
52     }
53
54     @Override
55     protected ThingHandler createHandler(Thing thing) {
56         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
57         logger.trace("**** Cm11AHandlerFactory.createHandler for {}", thingTypeUID.getAsString());
58
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);
65         }
66
67         return null;
68     }
69 }