]> git.basschouten.com Git - openhab-addons.git/blob
06289fcf36325e4a5a2e6793a76dc612a1ec1d78
[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.nanoleaf.internal;
14
15 import java.util.Collections;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.nanoleaf.internal.handler.NanoleafControllerHandler;
23 import org.openhab.binding.nanoleaf.internal.handler.NanoleafPanelHandler;
24 import org.openhab.core.io.net.http.HttpClientFactory;
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.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * The {@link NanoleafHandlerFactory} is responsible for creating the controller (bridge)
39  * and panel (thing) handlers.
40  *
41  * @author Martin Raepple - Initial contribution
42  * @author Kai Kreuzer - made discovery a handler service
43  */
44 @NonNullByDefault
45 @Component(configurationPid = "binding.nanoleaf", service = ThingHandlerFactory.class)
46 public class NanoleafHandlerFactory extends BaseThingHandlerFactory {
47
48     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
49             Stream.of(NanoleafBindingConstants.THING_TYPE_LIGHT_PANEL, NanoleafBindingConstants.THING_TYPE_CONTROLLER)
50                     .collect(Collectors.toSet()));
51
52     private final Logger logger = LoggerFactory.getLogger(NanoleafHandlerFactory.class);
53     private final HttpClientFactory httpClientFactory;
54
55     @Activate
56     public NanoleafHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
57         this.httpClientFactory = httpClientFactory;
58     }
59
60     @Override
61     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
63     }
64
65     @Nullable
66     @Override
67     protected ThingHandler createHandler(Thing thing) {
68         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
69         if (NanoleafBindingConstants.THING_TYPE_CONTROLLER.equals(thingTypeUID)) {
70             NanoleafControllerHandler handler = new NanoleafControllerHandler((Bridge) thing, this.httpClientFactory);
71             logger.debug("Nanoleaf controller handler created.");
72             return handler;
73         } else if (NanoleafBindingConstants.THING_TYPE_LIGHT_PANEL.equals(thingTypeUID)) {
74             NanoleafPanelHandler handler = new NanoleafPanelHandler(thing, this.httpClientFactory);
75             logger.debug("Nanoleaf panel handler created.");
76             return handler;
77         } else {
78             return null;
79         }
80     }
81 }