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.unifi.internal;
15 import static org.openhab.binding.unifi.internal.UniFiBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.eclipse.jetty.util.ssl.SslContextFactory;
21 import org.openhab.binding.unifi.internal.handler.UniFiClientThingHandler;
22 import org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler;
23 import org.openhab.binding.unifi.internal.handler.UniFiPoePortThingHandler;
24 import org.openhab.binding.unifi.internal.handler.UniFiSiteThingHandler;
25 import org.openhab.binding.unifi.internal.handler.UniFiWlanThingHandler;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.openhab.core.io.net.http.HttpClientInitializationException;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.ThingHandlerFactory;
34 import org.osgi.service.component.ComponentContext;
35 import org.osgi.service.component.annotations.Activate;
36 import org.osgi.service.component.annotations.Component;
37 import org.osgi.service.component.annotations.Reference;
40 * The {@link UniFiThingHandlerFactory} is responsible for creating things and thing
43 * @author Matthew Bowman - Initial contribution
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.unifi")
47 public class UniFiThingHandlerFactory extends BaseThingHandlerFactory {
49 private final HttpClient httpClient;
52 public UniFiThingHandlerFactory(@Reference final HttpClientFactory httpClientFactory) {
53 // [wip] mgb: disabled due to missing common name attributes with certs
54 // this.httpClient = httpClientFactory.getCommonHttpClient();
55 httpClient = new HttpClient(new SslContextFactory.Client(true));
58 } catch (final Exception e) {
59 throw new HttpClientInitializationException("Could not start HttpClient", e);
64 protected void deactivate(final ComponentContext componentContext) {
67 } catch (final Exception e) {
68 // Eat http client stop exception.
70 super.deactivate(componentContext);
75 public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
76 return ALL_THING_TYPE_SUPPORTED.contains(thingTypeUID);
80 protected @Nullable ThingHandler createHandler(final Thing thing) {
81 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
82 if (THING_TYPE_CONTROLLER.equals(thingTypeUID)) {
83 return new UniFiControllerThingHandler((Bridge) thing, httpClient);
84 } else if (THING_TYPE_SITE.equals(thingTypeUID)) {
85 return new UniFiSiteThingHandler(thing);
86 } else if (THING_TYPE_WLAN.equals(thingTypeUID)) {
87 return new UniFiWlanThingHandler(thing);
88 } else if (THING_TYPE_WIRELESS_CLIENT.equals(thingTypeUID) || THING_TYPE_WIRED_CLIENT.equals(thingTypeUID)) {
89 return new UniFiClientThingHandler(thing);
90 } else if (THING_TYPE_POE_PORT.equals(thingTypeUID)) {
91 return new UniFiPoePortThingHandler(thing);