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.openhab.binding.velux.internal.VeluxBindingConstants;
20 import org.openhab.binding.velux.internal.bridge.common.GetFirmware;
21 import org.openhab.binding.velux.internal.things.VeluxGwFirmware;
24 * Specific bridge communication message supported by the Velux bridge.
26 * Message semantic: Retrieval of Bridge 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 JCgetFirmware extends GetFirmware implements JsonBridgeCommunicationProtocol {
39 private static final String URL = "/api/v1/settings";
40 private static final String DESCRIPTION = "get firmware version";
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
51 * JsonVeluxBridge} for serializing.
56 * {"action":"getFirmware","params":{}}
60 private static class Request {
62 @SuppressWarnings("unused")
63 private String action;
65 @SuppressWarnings("unused")
66 private Map<String, String> params;
69 this.action = "getFirmware";
70 this.params = new HashMap<>();
75 * Bridge Communication Structure containing the version of the firmware.
77 * Used within structure {@link JCgetFirmware} to describe the software of the Bridge.
80 private static class BCfirmwareVersion {
82 * "version": "0.1.1.0.41.0"
84 private String version = VeluxBindingConstants.UNKNOWN;
88 * Bridge I/O Response message used by {@link org.openhab.binding.velux.internal.bridge.json.JsonVeluxBridge} for
89 * deserializing with including component access methods
91 * Expected JSON (sample):
95 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
97 * "deviceStatus":"IDLE",
98 * "data":{"version":"0.1.1.0.41.0"},
104 private static class Response {
105 @SuppressWarnings("unused")
106 private String token = VeluxBindingConstants.UNKNOWN;
107 private boolean result;
108 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
109 private BCfirmwareVersion data = new BCfirmwareVersion();
110 private String[] errors = {};
114 * Methods required for interface {@link BridgeCommunicationProtocol}.
118 public String name() {
123 public String getURL() {
128 public Object getObjectOfRequest() {
133 public Class<Response> getClassOfResponse() {
134 return Response.class;
138 public void setResponse(Object thisResponse) {
139 response = (Response) thisResponse;
143 public boolean isCommunicationSuccessful() {
144 return response.result;
148 public String getDeviceStatus() {
149 return response.deviceStatus;
153 public String[] getErrors() {
154 return response.errors;
158 * Methods in addition to interface {@link JsonBridgeCommunicationProtocol}.
161 public VeluxGwFirmware getFirmware() {
162 VeluxGwFirmware gwFirmware = new VeluxGwFirmware(response.data.version);