]> git.basschouten.com Git - openhab-addons.git/blob
44b4860f29865a074bd29bf2ac249933da28d57e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.touchwand.internal;
14
15 import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
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;
34
35 /**
36  * The {@link TouchWandHandlerFactory} is responsible for creating things and thing
37  * handlers.
38  *
39  * @author Roie Geron - Initial contribution
40  */
41
42 @Component(configurationPid = "binding.touchwand", service = ThingHandlerFactory.class)
43 @NonNullByDefault
44 public class TouchWandHandlerFactory extends BaseThingHandlerFactory {
45
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()));
49
50     private @NonNullByDefault({}) HttpClient httpClient;
51
52     @Override
53     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
54         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
55     }
56
57     @Override
58     protected @Nullable ThingHandler createHandler(Thing thing) {
59         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60
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);
77         }
78
79         return null;
80     }
81
82     @Reference
83     protected void setHttpClientFactory(HttpClientFactory httpClientFactory) {
84         this.httpClient = httpClientFactory.getCommonHttpClient();
85     }
86
87     protected void unsetHttpClientFactory(HttpClientFactory httpClientFactory) {
88         this.httpClient = null;
89     }
90 }