2 * Copyright (c) 2010-2023 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 java.util.Collections;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
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;
38 * The {@link NanoleafHandlerFactory} is responsible for creating the controller (bridge)
39 * and panel (thing) handlers.
41 * @author Martin Raepple - Initial contribution
42 * @author Kai Kreuzer - made discovery a handler service
45 @Component(configurationPid = "binding.nanoleaf", service = ThingHandlerFactory.class)
46 public class NanoleafHandlerFactory extends BaseThingHandlerFactory {
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()));
52 private final Logger logger = LoggerFactory.getLogger(NanoleafHandlerFactory.class);
53 private final HttpClientFactory httpClientFactory;
56 public NanoleafHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
57 this.httpClientFactory = httpClientFactory;
61 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
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.");
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.");