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.innogysmarthome.internal;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.openhab.binding.innogysmarthome.internal.handler.InnogyBridgeHandler;
23 import org.openhab.binding.innogysmarthome.internal.handler.InnogyDeviceHandler;
24 import org.openhab.core.auth.client.oauth2.OAuthFactory;
25 import org.openhab.core.io.net.http.HttpClientFactory;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Activate;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * The {@link InnogyHandlerFactory} is responsible for creating things and thing
42 * @author Oliver Kuhl - Initial contribution
43 * @author Hilbrand Bouwkamp - Refactored to use openHAB http and oauth2 libraries
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.innogysmarthome")
47 public class InnogyHandlerFactory extends BaseThingHandlerFactory implements ThingHandlerFactory {
49 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
50 .concat(InnogyBridgeHandler.SUPPORTED_THING_TYPES.stream(),
51 InnogyDeviceHandler.SUPPORTED_THING_TYPES.stream())
52 .collect(Collectors.toSet());
54 private final Logger logger = LoggerFactory.getLogger(InnogyHandlerFactory.class);
56 private final OAuthFactory oAuthFactory;
57 private final HttpClient httpClient;
60 public InnogyHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory) {
61 this.oAuthFactory = oAuthFactory;
62 httpClient = httpClientFactory.getCommonHttpClient();
66 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
71 protected @Nullable ThingHandler createHandler(Thing thing) {
72 if (InnogyBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
73 return new InnogyBridgeHandler((Bridge) thing, oAuthFactory, httpClient);
74 } else if (InnogyDeviceHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
75 return new InnogyDeviceHandler(thing);
77 logger.debug("Unsupported thing {}.", thing.getThingTypeUID());