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 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 static Request request = new Request();
43 private static Response response = new Response();
49 private static class ParamsLogin {
50 @SuppressWarnings("unused")
51 private String password = VeluxBindingConstants.UNKNOWN;
55 * Bridge I/O Request message used by {@link JsonVeluxBridge}
61 * {"action":"login","params":{"password":"PASSWORD"}}
65 private static class Request {
67 @SuppressWarnings("unused")
68 private final String action = "login";
69 private ParamsLogin params;
72 this.params = new ParamsLogin();
77 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
80 * <B>Expected JSON (sample):</B>
83 * '{"token": "PHPnfLda71xfGlxoYEOTGQ==", "result": true, "deviceStatus": "IDLE", "data": {}, "errors": [] }'
87 private static class Response {
88 private String token = VeluxBindingConstants.UNKNOWN;
89 private boolean result;
90 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
91 @SuppressWarnings("unused")
92 private @Nullable Object data;
93 private String[] errors = {};
95 public String getToken() {
99 public boolean getResult() {
109 logger.trace("JClogin(constructor) called.");
113 * Methods required for interface {@link BridgeCommunicationProtocol}.
117 public String name() {
122 public String getURL() {
127 public Object getObjectOfRequest() {
132 public Class<Response> getClassOfResponse() {
133 return Response.class;
137 public void setResponse(Object thisResponse) {
138 response = (Response) thisResponse;
142 public boolean isCommunicationSuccessful() {
143 return response.getResult();
147 public String getDeviceStatus() {
148 return response.deviceStatus;
152 public String[] getErrors() {
153 return response.errors;
157 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
161 public void setPassword(String thisPassword) {
162 logger.trace("setPassword() called.");
163 request.params.password = thisPassword;
167 public String getAuthToken() {
168 return response.getToken();