]> git.basschouten.com Git - openhab-addons.git/blob
5d74f1e516e864c0c3d54a4c8150343e8e0693d3
[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.homematic.internal.communicator;
14
15 import java.io.IOException;
16
17 import org.eclipse.jetty.client.HttpClient;
18 import org.openhab.binding.homematic.internal.common.HomematicConfig;
19 import org.openhab.binding.homematic.internal.communicator.client.RpcClient;
20 import org.openhab.binding.homematic.internal.communicator.client.XmlRpcClient;
21
22 /**
23  * Factory which evaluates the type of the Homematic gateway and instantiates the appropriate class.
24  *
25  * @author Gerhard Riegler - Initial contribution
26  */
27 public class HomematicGatewayFactory {
28
29     /**
30      * Creates the HomematicGateway.
31      */
32     public static HomematicGateway createGateway(String id, HomematicConfig config,
33             HomematicGatewayAdapter gatewayAdapter, HttpClient httpClient) throws IOException {
34         loadGatewayInfo(config, id, httpClient);
35         if (config.getGatewayInfo().isCCU()) {
36             return new CcuGateway(id, config, gatewayAdapter, httpClient);
37         } else if (config.getGatewayInfo().isHomegear()) {
38             return new HomegearGateway(id, config, gatewayAdapter, httpClient);
39         } else {
40             return new DefaultGateway(id, config, gatewayAdapter, httpClient);
41         }
42     }
43
44     /**
45      * Loads some metadata about the type of the Homematic gateway.
46      */
47     private static void loadGatewayInfo(HomematicConfig config, String id, HttpClient httpClient) throws IOException {
48         RpcClient<String> rpcClient = new XmlRpcClient(config, httpClient);
49         try {
50             config.setGatewayInfo(rpcClient.getGatewayInfo(id));
51         } finally {
52             rpcClient.dispose();
53         }
54     }
55 }