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.touchwand.internal;
15 import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jetty.client.HttpClient;
25 import org.openhab.core.io.net.http.HttpClientFactory;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
36 * The {@link TouchWandHandlerFactory} is responsible for creating things and thing
39 * @author Roie Geron - Initial contribution
42 @Component(configurationPid = "binding.touchwand", service = ThingHandlerFactory.class)
44 public class TouchWandHandlerFactory extends BaseThingHandlerFactory {
46 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
47 .unmodifiableSet(Stream.concat(TouchWandBridgeHandler.SUPPORTED_THING_TYPES.stream(),
48 TouchWandBaseUnitHandler.SUPPORTED_THING_TYPES.stream()).collect(Collectors.toSet()));
50 private @NonNullByDefault({}) HttpClient httpClient;
53 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
54 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
58 protected @Nullable ThingHandler createHandler(Thing thing) {
59 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
61 if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
62 return new TouchWandBridgeHandler((Bridge) thing, httpClient, bundleContext);
63 } else if (THING_TYPE_SWITCH.equals(thingTypeUID)) {
64 return new TouchWandSwitchHandler(thing);
65 } else if (THING_TYPE_SHUTTER.equals(thingTypeUID)) {
66 return new TouchWandShutterHandler(thing);
67 } else if (THING_TYPE_WALLCONTROLLER.equals(thingTypeUID)) {
68 return new TouchWandWallControllerHandler(thing);
69 } else if (THING_TYPE_DIMMER.equals(thingTypeUID)) {
70 return new TouchWandDimmerHandler(thing);
71 } else if (THING_TYPE_ALARMSENSOR.equals(thingTypeUID)) {
72 return new TouchWandAlarmSensorHandler(thing);
73 } else if (THING_TYPE_BSENSOR.equals(thingTypeUID)) {
74 return new TouchWandBSensorHandler(thing);
75 } else if (THING_TYPE_THERMOSTAT.equals(thingTypeUID)) {
76 return new TouchWandThermostatHandler(thing);
83 protected void setHttpClientFactory(HttpClientFactory httpClientFactory) {
84 this.httpClient = httpClientFactory.getCommonHttpClient();
87 protected void unsetHttpClientFactory(HttpClientFactory httpClientFactory) {
88 this.httpClient = null;