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.unifi.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.jetty.client.HttpClient;
18 import org.eclipse.jetty.util.ssl.SslContextFactory;
19 import org.openhab.binding.unifi.internal.handler.UniFiClientThingHandler;
20 import org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler;
21 import org.openhab.core.io.net.http.HttpClientFactory;
22 import org.openhab.core.io.net.http.HttpClientInitializationException;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
34 * The {@link UniFiThingHandlerFactory} is responsible for creating things and thing
37 * @author Matthew Bowman - Initial contribution
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.unifi")
41 public class UniFiThingHandlerFactory extends BaseThingHandlerFactory {
43 private final HttpClient httpClient;
46 public UniFiThingHandlerFactory(@Reference final HttpClientFactory httpClientFactory) {
47 // [wip] mgb: disabled due to missing common name attributes with certs
48 // this.httpClient = httpClientFactory.getCommonHttpClient();
49 httpClient = new HttpClient(new SslContextFactory.Client(true));
52 } catch (Exception e) {
53 throw new HttpClientInitializationException("Could not start HttpClient", e);
58 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
59 return UniFiControllerThingHandler.supportsThingType(thingTypeUID)
60 || UniFiClientThingHandler.supportsThingType(thingTypeUID);
64 protected @Nullable ThingHandler createHandler(Thing thing) {
65 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
66 if (UniFiControllerThingHandler.supportsThingType(thingTypeUID)) {
67 return new UniFiControllerThingHandler((Bridge) thing, httpClient);
68 } else if (UniFiClientThingHandler.supportsThingType(thingTypeUID)) {
69 return new UniFiClientThingHandler(thing);