]> git.basschouten.com Git - openhab-addons.git/blob
b26871a356a05caa3c75b3e14fa7b18546258fff
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.atlona.internal;
14
15 import static org.openhab.binding.atlona.internal.AtlonaBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19
20 import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Capabilities;
21 import org.openhab.binding.atlona.internal.pro3.AtlonaPro3Handler;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.thing.binding.ThingHandlerFactory;
27 import org.osgi.service.component.annotations.Component;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * The {@link org.openhab.binding.atlona.internal.AtlonaHandlerFactory} is responsible for creating things and thing
33  * handlers.
34  *
35  * @author Tim Roberts - Initial contribution
36  * @author Michael Lobstein - Add support for AT-PRO3HD66M
37  */
38 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.atlona")
39 public class AtlonaHandlerFactory extends BaseThingHandlerFactory {
40
41     private final Logger logger = LoggerFactory.getLogger(AtlonaHandlerFactory.class);
42
43     /**
44      * The set of supported Atlona products
45      */
46     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PRO3_44M, THING_TYPE_PRO3_66M,
47             THING_TYPE_PRO3_88M, THING_TYPE_PRO3_1616M, THING_TYPE_PRO3HD_66M);
48
49     /**
50      * {@inheritDoc}
51      *
52      * Simply returns true if the given thingTypeUID is within {@link #SUPPORTED_THING_TYPES_UIDS}
53      */
54     @Override
55     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
56         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
57     }
58
59     /**
60      * {@inheritDoc}
61      *
62      * Creates the handler for the given thing given its thingTypeUID
63      */
64     @Override
65     protected ThingHandler createHandler(Thing thing) {
66         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
67
68         if (thingTypeUID.equals(THING_TYPE_PRO3_44M)) {
69             return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Collections.singleton(5), true));
70         }
71
72         if (thingTypeUID.equals(THING_TYPE_PRO3_66M)) {
73             return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(8, 4, Set.of(6, 8), true));
74         }
75
76         if (thingTypeUID.equals(THING_TYPE_PRO3_88M)) {
77             return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(10, 6, Set.of(8, 10), true));
78         }
79
80         if (thingTypeUID.equals(THING_TYPE_PRO3_1616M)) {
81             return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Set.of(17, 18, 19, 20), true));
82         }
83
84         if (thingTypeUID.equals(THING_TYPE_PRO3HD_66M)) {
85             return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(0, 0, Set.of(1, 2, 3, 4, 5, 6), false));
86         }
87
88         logger.warn("Unknown binding: {}: {}", thingTypeUID.getId(), thingTypeUID.getBindingId());
89         return null;
90     }
91 }