2 * Copyright (c) 2010-2024 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 httpClient = httpClientFactory.createHttpClient(BINDING_ID, new SslContextFactory.Client(true));
56 } catch (final Exception e) {
57 throw new HttpClientInitializationException("Could not start HttpClient", e);
62 protected void deactivate(final ComponentContext componentContext) {
65 } catch (final Exception e) {
66 // Eat http client stop exception.
68 super.deactivate(componentContext);
73 public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
74 return ALL_THING_TYPE_SUPPORTED.contains(thingTypeUID);
78 protected @Nullable ThingHandler createHandler(final Thing thing) {
79 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
80 if (THING_TYPE_CONTROLLER.equals(thingTypeUID)) {
81 return new UniFiControllerThingHandler((Bridge) thing, httpClient);
82 } else if (THING_TYPE_SITE.equals(thingTypeUID)) {
83 return new UniFiSiteThingHandler(thing);
84 } else if (THING_TYPE_WLAN.equals(thingTypeUID)) {
85 return new UniFiWlanThingHandler(thing);
86 } else if (THING_TYPE_WIRELESS_CLIENT.equals(thingTypeUID) || THING_TYPE_WIRED_CLIENT.equals(thingTypeUID)) {
87 return new UniFiClientThingHandler(thing);
88 } else if (THING_TYPE_POE_PORT.equals(thingTypeUID)) {
89 return new UniFiPoePortThingHandler(thing);