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.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":{}}
55 private static class Request {
57 @SuppressWarnings("unused")
58 private String action;
59 @SuppressWarnings("unused")
60 private Map<String, String> params;
63 this.action = "logout";
64 this.params = new HashMap<>();
69 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
72 * Expected JSON (sample):
75 * '{"token": "PHPnfLda71xfGlxoYEOTGQ==", "result": true, "deviceStatus": "IDLE", "data": {}, "errors": [] }'
79 private static class Response {
80 @SuppressWarnings("unused")
81 private String token = VeluxBindingConstants.UNKNOWN;
82 private boolean result;
83 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
84 @SuppressWarnings("unused")
85 private @Nullable Object data = null;
86 private String[] errors = {};
88 public boolean getResult() {
94 * Methods required for interface {@link BridgeCommunicationProtocol}.
98 public String name() {
103 public String getURL() {
108 public Object getObjectOfRequest() {
113 public Class<Response> getClassOfResponse() {
114 return Response.class;
118 public void setResponse(Object thisResponse) {
119 response = (Response) thisResponse;
123 public boolean isCommunicationSuccessful() {
124 return response.getResult();
128 public String getDeviceStatus() {
129 return response.deviceStatus;
133 public String[] getErrors() {
134 return response.errors;