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.velux.internal.bridge.json;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.velux.internal.VeluxBindingConstants;
20 import org.openhab.binding.velux.internal.bridge.common.BridgeCommunicationProtocol;
21 import org.openhab.binding.velux.internal.bridge.common.GetLANConfig;
22 import org.openhab.binding.velux.internal.things.VeluxGwLAN;
25 * Specific bridge communication message supported by the Velux bridge.
27 * Message semantic: Retrieval of LAN configuration.
30 * It defines information how to send query and receive answer through the
31 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
32 * as described by the {@link org.openhab.binding.velux.internal.bridge.json.JsonBridgeCommunicationProtocol
33 * BridgeCommunicationProtocol}.
35 * @author Guenther Schreiner - Initial contribution.
38 class JCgetLANConfig extends GetLANConfig implements BridgeCommunicationProtocol, JsonBridgeCommunicationProtocol {
40 private static final String URL = "/api/v1/lan";
41 private static final String DESCRIPTION = "get LAN configuration";
43 private Request request = new Request();
44 private Response response = new Response();
51 * Bridge I/O Request message used by {@link JsonVeluxBridge}
57 * {"action":"get","params":{}}
60 private static class Request {
62 @SuppressWarnings("unused")
63 private String action;
65 @SuppressWarnings("unused")
66 private Map<String, String> params;
70 this.params = new HashMap<>();
75 * Bridge Communication Structure containing the network parameters.
77 * Used within structure {@link JCgetLANConfig} to describe the network connectivity of the Bridge.
80 * {"ipAddress":"192.168.45.9","subnetMask":"255.255.255.0","defaultGateway":"192.168.45.129","dhcp":false}
83 private static class BCLANConfig {
84 private String ipAddress = VeluxBindingConstants.UNKNOWN;
85 private String subnetMask = VeluxBindingConstants.UNKNOWN;
86 private String defaultGateway = VeluxBindingConstants.UNKNOWN;
90 public String toString() {
91 return String.format("ipAddress=%s,subnetMask=%s,defaultGateway=%s,dhcp=%s", this.ipAddress,
92 this.subnetMask, this.defaultGateway, this.dhcp ? "on" : "off");
97 * Bridge I/O Response message used by {@link JsonVeluxBridge} for unmarshalling with including component access
100 * Expected JSON (sample):
104 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
106 * "deviceStatus":"IDLE",
107 * "data":"ipAddress":"192.168.45.9","subnetMask":"255.255.255.0","defaultGateway":"192.168.45.129","dhcp":false},
112 private static class Response {
113 @SuppressWarnings("unused")
114 private String token = VeluxBindingConstants.UNKNOWN;
115 private boolean result;
116 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
117 private BCLANConfig data = new BCLANConfig();
118 private String[] errors = {};
120 public boolean getResult() {
124 public String getDeviceStatus() {
128 public String[] getErrors() {
134 * Methods required for interface {@link BridgeCommunicationProtocol}.
138 public String name() {
143 public String getURL() {
148 public Object getObjectOfRequest() {
153 public Class<Response> getClassOfResponse() {
154 return Response.class;
158 public void setResponse(Object response) {
159 this.response = (Response) response;
163 public boolean isCommunicationSuccessful() {
164 return response.getResult();
168 public String getDeviceStatus() {
169 return response.getDeviceStatus();
173 public String[] getErrors() {
174 return response.getErrors();
178 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
181 public VeluxGwLAN getLANConfig() {
182 VeluxGwLAN gwLAN = new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask,
183 response.data.defaultGateway, response.data.dhcp);