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.vesync.internal;
15 import static org.openhab.binding.vesync.internal.VeSyncConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.openhab.binding.vesync.internal.api.IHttpClientProvider;
23 import org.openhab.binding.vesync.internal.handlers.VeSyncBridgeHandler;
24 import org.openhab.binding.vesync.internal.handlers.VeSyncDeviceAirHumidifierHandler;
25 import org.openhab.binding.vesync.internal.handlers.VeSyncDeviceAirPurifierHandler;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
37 * The {@link org.openhab.binding.vesync.internal.VeSyncHandlerFactory} is responsible for creating
38 * things and thing handlers.
40 * @author David Goodyear - Initial contribution
43 @Component(configurationPid = "binding.vesync", service = ThingHandlerFactory.class)
44 public class VeSyncHandlerFactory extends BaseThingHandlerFactory implements IHttpClientProvider {
46 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BRIDGE,
47 THING_TYPE_AIR_PURIFIER, THING_TYPE_AIR_HUMIDIFIER);
49 private @Nullable HttpClient httpClientRef = null;
52 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
53 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60 if (VeSyncDeviceAirPurifierHandler.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
61 return new VeSyncDeviceAirPurifierHandler(thing);
62 } else if (VeSyncDeviceAirHumidifierHandler.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
63 return new VeSyncDeviceAirHumidifierHandler(thing);
64 } else if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
65 return new VeSyncBridgeHandler((Bridge) thing, this);
72 protected void setHttpClientFactory(HttpClientFactory httpClientFactory) {
73 httpClientRef = httpClientFactory.getCommonHttpClient();
77 public @Nullable HttpClient getHttpClient() {