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.livisismarthome.internal;
15 import static org.openhab.binding.livisismarthome.internal.LivisiBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.openhab.binding.livisismarthome.internal.handler.LivisiBridgeHandler;
21 import org.openhab.binding.livisismarthome.internal.handler.LivisiDeviceHandler;
22 import org.openhab.core.auth.client.oauth2.OAuthFactory;
23 import org.openhab.core.io.net.http.HttpClientFactory;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Activate;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Reference;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * The {@link LivisiHandlerFactory} is responsible for creating things and thing
40 * @author Oliver Kuhl - Initial contribution
41 * @author Hilbrand Bouwkamp - Refactored to use openHAB http and oauth2 libraries
42 * @author Sven Strohschein - Renamed from Innogy to Livisi
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.livisismarthome")
46 public class LivisiHandlerFactory extends BaseThingHandlerFactory implements ThingHandlerFactory {
48 private final Logger logger = LoggerFactory.getLogger(LivisiHandlerFactory.class);
50 private final OAuthFactory oAuthFactory;
51 private final HttpClient httpClient;
54 public LivisiHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory) {
55 this.oAuthFactory = oAuthFactory;
56 this.httpClient = httpClientFactory.getCommonHttpClient();
60 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
65 protected @Nullable ThingHandler createHandler(Thing thing) {
66 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
67 if (THING_TYPE_BRIDGE.equals(thingTypeUID) || SUPPORTED_DEVICE_THING_TYPES.contains(thingTypeUID)) {
68 if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
69 return new LivisiBridgeHandler((Bridge) thing, oAuthFactory, httpClient);
70 } else if (SUPPORTED_DEVICE_THING_TYPES.contains(thingTypeUID)) {
71 return new LivisiDeviceHandler(thing);
74 logger.debug("Unsupported thing {}.", thingTypeUID);