]> git.basschouten.com Git - openhab-addons.git/blob
0e25ed82676fba6f896352f335cf570014bb8a15
[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.livisismarthome.internal;
14
15 import static org.openhab.binding.livisismarthome.internal.LivisiBindingConstants.*;
16
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;
35
36 /**
37  * The {@link LivisiHandlerFactory} is responsible for creating things and thing
38  * handlers.
39  *
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
43  */
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.livisismarthome")
45 @NonNullByDefault
46 public class LivisiHandlerFactory extends BaseThingHandlerFactory implements ThingHandlerFactory {
47
48     private final Logger logger = LoggerFactory.getLogger(LivisiHandlerFactory.class);
49
50     private final OAuthFactory oAuthFactory;
51     private final HttpClient httpClient;
52
53     @Activate
54     public LivisiHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory) {
55         this.oAuthFactory = oAuthFactory;
56         this.httpClient = httpClientFactory.getCommonHttpClient();
57     }
58
59     @Override
60     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61         return SUPPORTED_THING_TYPES.contains(thingTypeUID);
62     }
63
64     @Override
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);
72             }
73         }
74         logger.debug("Unsupported thing {}.", thingTypeUID);
75         return null;
76     }
77 }