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.GetWLANConfig;
21 import org.openhab.binding.velux.internal.things.VeluxGwWLAN;
24 * Specific bridge communication message supported by the Velux bridge.
26 * Message semantic: Retrieval of WLAN configuration.
29 * It defines information how to send query and receive answer through the
30 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
31 * as described by the {@link org.openhab.binding.velux.internal.bridge.json.JsonBridgeCommunicationProtocol
32 * BridgeCommunicationProtocol}.
34 * @author Guenther Schreiner - Initial contribution.
37 class JCgetWLANConfig extends GetWLANConfig implements JsonBridgeCommunicationProtocol {
39 private static final String URL = "/api/v1/settings";
40 private static final String DESCRIPTION = "get WLAN configuration";
42 private Request request = new Request();
43 private Response response = new Response();
50 * Bridge I/O Request message used by {@link org.openhab.binding.velux.internal.bridge.json.JsonVeluxBridge
57 * {"action":"wifi","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 version of the firmware.
78 * Used within structure {@link JCgetWLANConfig} to describe the network connectivity of the Bridge.
81 * {"password":"Esf56mxqFY","name":"VELUX_KLF_847C"}
85 private static class BCWLANConfig {
87 private String password = VeluxBindingConstants.UNKNOWN;
88 private String name = VeluxBindingConstants.UNKNOWN;
91 public String toString() {
92 return String.format("SSID=%s,password=********", this.name);
97 * Bridge I/O Response message used by {@link JsonBridgeCommunicationProtocol} for deserialization with including
101 * Expected JSON (sample):
105 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
107 * "deviceStatus":"IDLE",
108 * "data":{"password":"Esf56mxqFY","name":"VELUX_KLF_847C"},
114 private static class Response {
115 @SuppressWarnings("unused")
116 private String token = VeluxBindingConstants.UNKNOWN;
117 private boolean result;
118 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
119 private BCWLANConfig data = new BCWLANConfig();
120 private String[] errors = {};
122 public boolean getResult() {
127 public String toString() {
128 return data.toString();
133 * Methods required for interface {@link BridgeCommunicationProtocol}.
137 public String name() {
142 public String getURL() {
147 public Object getObjectOfRequest() {
152 public Class<Response> getClassOfResponse() {
153 return Response.class;
157 public void setResponse(Object response) {
158 this.response = (Response) response;
162 public boolean isCommunicationSuccessful() {
163 return response.getResult();
167 public String getDeviceStatus() {
168 return response.deviceStatus;
172 public String[] getErrors() {
173 return response.errors;
177 * Methods in addition to interface {@link JsonBridgeCommunicationProtocol}.
180 public VeluxGwWLAN getWLANConfig() {
181 VeluxGwWLAN gwWLAN = new VeluxGwWLAN(response.data.name, response.data.password);