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.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":{}}
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 version of the firmware.
77 * Used within structure {@link JCgetWLANConfig} to describe the network connectivity of the Bridge.
80 * {"password":"Esf56mxqFY","name":"VELUX_KLF_847C"}
83 private static class BCWLANConfig {
85 private String password = VeluxBindingConstants.UNKNOWN;
86 private String name = VeluxBindingConstants.UNKNOWN;
89 public String toString() {
90 return String.format("SSID=%s,password=********", this.name);
95 * Bridge I/O Response message used by {@link JsonBridgeCommunicationProtocol} for deserialization with including
99 * Expected JSON (sample):
103 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
105 * "deviceStatus":"IDLE",
106 * "data":{"password":"Esf56mxqFY","name":"VELUX_KLF_847C"},
111 private static class Response {
112 @SuppressWarnings("unused")
113 private String token = VeluxBindingConstants.UNKNOWN;
114 private boolean result;
115 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
116 private BCWLANConfig data = new BCWLANConfig();
117 private String[] errors = {};
119 public boolean getResult() {
124 public String toString() {
125 return data.toString();
130 * Methods required for interface {@link BridgeCommunicationProtocol}.
134 public String name() {
139 public String getURL() {
144 public Object getObjectOfRequest() {
149 public Class<Response> getClassOfResponse() {
150 return Response.class;
154 public void setResponse(Object response) {
155 this.response = (Response) response;
159 public boolean isCommunicationSuccessful() {
160 return response.getResult();
164 public String getDeviceStatus() {
165 return response.deviceStatus;
169 public String[] getErrors() {
170 return response.errors;
174 * Methods in addition to interface {@link JsonBridgeCommunicationProtocol}.
177 public VeluxGwWLAN getWLANConfig() {
178 return new VeluxGwWLAN(response.data.name, response.data.password);