2 * Copyright (c) 2010-2020 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":{}}
61 private static class Request {
63 @SuppressWarnings("unused")
64 private String action;
66 @SuppressWarnings("unused")
67 private Map<String, String> params;
71 this.params = new HashMap<>();
76 * Bridge Communication Structure containing the network parameters.
78 * Used within structure {@link JCgetLANConfig} to describe the network connectivity of the Bridge.
81 * {"ipAddress":"192.168.45.9","subnetMask":"255.255.255.0","defaultGateway":"192.168.45.129","dhcp":false}
85 private static class BCLANConfig {
86 private String ipAddress = VeluxBindingConstants.UNKNOWN;
87 private String subnetMask = VeluxBindingConstants.UNKNOWN;
88 private String defaultGateway = VeluxBindingConstants.UNKNOWN;
92 public String toString() {
93 return String.format("ipAddress=%s,subnetMask=%s,defaultGateway=%s,dhcp=%s", this.ipAddress,
94 this.subnetMask, this.defaultGateway, this.dhcp ? "on" : "off");
99 * Bridge I/O Response message used by {@link JsonVeluxBridge} for unmarshalling with including component access
102 * Expected JSON (sample):
106 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
108 * "deviceStatus":"IDLE",
109 * "data":"ipAddress":"192.168.45.9","subnetMask":"255.255.255.0","defaultGateway":"192.168.45.129","dhcp":false},
115 private static class Response {
116 @SuppressWarnings("unused")
117 private String token = VeluxBindingConstants.UNKNOWN;
118 private boolean result;
119 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
120 private BCLANConfig data = new BCLANConfig();
121 private String[] errors = {};
123 public boolean getResult() {
127 public String getDeviceStatus() {
131 public String[] getErrors() {
137 * Methods required for interface {@link BridgeCommunicationProtocol}.
141 public String name() {
146 public String getURL() {
151 public Object getObjectOfRequest() {
156 public Class<Response> getClassOfResponse() {
157 return Response.class;
161 public void setResponse(Object response) {
162 this.response = (Response) response;
166 public boolean isCommunicationSuccessful() {
167 return response.getResult();
171 public String getDeviceStatus() {
172 return response.getDeviceStatus();
176 public String[] getErrors() {
177 return response.getErrors();
181 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
184 public VeluxGwLAN getLANConfig() {
185 VeluxGwLAN gwLAN = new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask,
186 response.data.defaultGateway, response.data.dhcp);