2 * Copyright (c) 2010-2024 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.homematic.internal.communicator;
15 import java.io.IOException;
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;
23 * Factory which evaluates the type of the Homematic gateway and instantiates the appropriate class.
25 * @author Gerhard Riegler - Initial contribution
27 public class HomematicGatewayFactory {
30 * Creates the HomematicGateway.
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);
40 return new DefaultGateway(id, config, gatewayAdapter, httpClient);
45 * Loads some metadata about the type of the Homematic gateway.
47 private static void loadGatewayInfo(HomematicConfig config, String id, HttpClient httpClient) throws IOException {
48 RpcClient<String> rpcClient = new XmlRpcClient(config, httpClient);
50 config.setGatewayInfo(rpcClient.getGatewayInfo(id));