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.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.velux.internal.VeluxBindingConstants;
21 import org.openhab.binding.velux.internal.bridge.common.Logout;
24 * Specific bridge communication message supported by the Velux bridge.
26 * Message semantic: Communication to deauthenticate itself, resulting in a return of current bridge state.
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 JClogout extends Logout implements JsonBridgeCommunicationProtocol {
39 private static final String URL = "/api/v1/auth";
40 private static final String DESCRIPTION = "deauthenticate / logout";
42 private Request request = new Request();
43 private Response response = new Response();
46 * Bridge I/O Request message used by {@link JsonVeluxBridge} for serializing.
51 * {"action":"logout","params":{}}
54 private static class Request {
56 @SuppressWarnings("unused")
57 private String action;
58 @SuppressWarnings("unused")
59 private Map<String, String> params;
62 this.action = "logout";
63 this.params = new HashMap<>();
68 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
71 * Expected JSON (sample):
74 * '{"token": "PHPnfLda71xfGlxoYEOTGQ==", "result": true, "deviceStatus": "IDLE", "data": {}, "errors": [] }'
77 private static class Response {
78 @SuppressWarnings("unused")
79 private String token = VeluxBindingConstants.UNKNOWN;
80 private boolean result;
81 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
82 @SuppressWarnings("unused")
83 private @Nullable Object data = null;
84 private String[] errors = {};
86 public boolean getResult() {
92 * Methods required for interface {@link BridgeCommunicationProtocol}.
96 public String name() {
101 public String getURL() {
106 public Object getObjectOfRequest() {
111 public Class<Response> getClassOfResponse() {
112 return Response.class;
116 public void setResponse(Object thisResponse) {
117 response = (Response) thisResponse;
121 public boolean isCommunicationSuccessful() {
122 return response.getResult();
126 public String getDeviceStatus() {
127 return response.deviceStatus;
131 public String[] getErrors() {
132 return response.errors;