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