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.mynice.internal;
15 import static org.openhab.binding.mynice.internal.MyNiceBindingConstants.*;
17 import java.security.KeyManagementException;
18 import java.security.NoSuchAlgorithmException;
21 import javax.net.ssl.SSLContext;
22 import javax.net.ssl.SSLSocketFactory;
23 import javax.net.ssl.TrustManager;
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.openhab.binding.mynice.internal.handler.GateHandler;
28 import org.openhab.binding.mynice.internal.handler.It4WifiHandler;
29 import org.openhab.core.io.net.http.TrustAllTrustManager;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
34 import org.openhab.core.thing.binding.ThingHandler;
35 import org.openhab.core.thing.binding.ThingHandlerFactory;
36 import org.osgi.service.component.annotations.Activate;
37 import org.osgi.service.component.annotations.Component;
40 * The {@link MyNiceHandlerFactory} is responsible for creating thing handlers.
42 * @author Gaƫl L'hopital - Initial contribution
45 @Component(configurationPid = "binding.mynice", service = ThingHandlerFactory.class)
46 public class MyNiceHandlerFactory extends BaseThingHandlerFactory {
47 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(BRIDGE_TYPE_IT4WIFI, THING_TYPE_SWING,
49 private final SSLSocketFactory socketFactory;
52 public MyNiceHandlerFactory() {
54 SSLContext sslContext = SSLContext.getInstance("SSL");
55 sslContext.init(null, new TrustManager[] { TrustAllTrustManager.getInstance() }, null);
56 socketFactory = sslContext.getSocketFactory();
57 } catch (NoSuchAlgorithmException | KeyManagementException e) {
58 throw new IllegalArgumentException(e);
63 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68 protected @Nullable ThingHandler createHandler(Thing thing) {
69 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
71 if (BRIDGE_TYPE_IT4WIFI.equals(thingTypeUID)) {
72 return new It4WifiHandler((Bridge) thing, socketFactory);
73 } else if (THING_TYPE_SWING.equals(thingTypeUID)) {
74 return new GateHandler(thing);
75 } else if (THING_TYPE_SLIDING.equals(thingTypeUID)) {
76 return new GateHandler(thing);