2 * Copyright (c) 2010-2022 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.velux.internal.VeluxBindingConstants;
18 import org.openhab.binding.velux.internal.bridge.common.Login;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Specific bridge communication message supported by the Velux bridge.
25 * Message semantic: Communication to authenticate itself, resulting in a return of current bridge state.
28 * It defines information how to send query and receive answer through the
29 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
30 * as described by the {@link org.openhab.binding.velux.internal.bridge.json.JsonBridgeCommunicationProtocol
31 * BridgeCommunicationProtocol}.
33 * @author Guenther Schreiner - Initial contribution.
36 class JClogin extends Login implements JsonBridgeCommunicationProtocol {
37 private final Logger logger = LoggerFactory.getLogger(JClogin.class);
39 private static final String URL = "/api/v1/auth";
40 private static final String DESCRIPTION = "authenticate / login";
42 private Request request = new Request();
43 private Response response = new Response();
48 private static class ParamsLogin {
49 @SuppressWarnings("unused")
50 private String password = VeluxBindingConstants.UNKNOWN;
54 * Bridge I/O Request message used by {@link JsonVeluxBridge}
60 * {"action":"login","params":{"password":"PASSWORD"}}
63 private static class Request {
65 @SuppressWarnings("unused")
66 private final String action = "login";
67 private ParamsLogin params;
70 this.params = new ParamsLogin();
75 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
78 * <B>Expected JSON (sample):</B>
81 * '{"token": "PHPnfLda71xfGlxoYEOTGQ==", "result": true, "deviceStatus": "IDLE", "data": {}, "errors": [] }'
84 private static class Response {
85 private String token = VeluxBindingConstants.UNKNOWN;
86 private boolean result;
87 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
88 @SuppressWarnings("unused")
89 private @Nullable Object data;
90 private String[] errors = {};
92 public String getToken() {
96 public boolean getResult() {
106 logger.trace("JClogin(constructor) called.");
110 * Methods required for interface {@link BridgeCommunicationProtocol}.
114 public String name() {
119 public String getURL() {
124 public Object getObjectOfRequest() {
129 public Class<Response> getClassOfResponse() {
130 return Response.class;
134 public void setResponse(Object thisResponse) {
135 response = (Response) thisResponse;
139 public boolean isCommunicationSuccessful() {
140 return response.getResult();
144 public String getDeviceStatus() {
145 return response.deviceStatus;
149 public String[] getErrors() {
150 return response.errors;
154 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
158 public void setPassword(String thisPassword) {
159 logger.trace("setPassword() called.");
160 request.params.password = thisPassword;
164 public String getAuthToken() {
165 return response.getToken();