2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nanoleaf.internal;
15 import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jetty.client.HttpClient;
25 import org.openhab.binding.nanoleaf.internal.handler.NanoleafControllerHandler;
26 import org.openhab.binding.nanoleaf.internal.handler.NanoleafPanelHandler;
27 import org.openhab.core.io.net.http.HttpClientFactory;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.ThingHandlerFactory;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * The {@link NanoleafHandlerFactory} is responsible for creating the controller (bridge)
42 * and panel (thing) handlers.
44 * @author Martin Raepple - Initial contribution
45 * @author Kai Kreuzer - made discovery a handler service
48 @Component(configurationPid = "binding.nanoleaf", service = ThingHandlerFactory.class)
49 public class NanoleafHandlerFactory extends BaseThingHandlerFactory {
51 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
52 .unmodifiableSet(Stream.of(THING_TYPE_LIGHT_PANEL, THING_TYPE_CONTROLLER).collect(Collectors.toSet()));
54 private final Logger logger = LoggerFactory.getLogger(NanoleafHandlerFactory.class);
55 private final HttpClient httpClient;
58 public NanoleafHandlerFactory(@Reference final HttpClientFactory httpClientFactory) {
59 this.httpClient = httpClientFactory.getCommonHttpClient();
63 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68 protected @Nullable ThingHandler createHandler(Thing thing) {
69 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
71 if (THING_TYPE_CONTROLLER.equals(thingTypeUID)) {
72 NanoleafControllerHandler handler = new NanoleafControllerHandler((Bridge) thing, httpClient);
73 logger.debug("Nanoleaf controller handler created.");
75 } else if (THING_TYPE_LIGHT_PANEL.equals(thingTypeUID)) {
76 NanoleafPanelHandler handler = new NanoleafPanelHandler(thing, httpClient);
77 logger.debug("Nanoleaf panel handler created.");