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.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":{}}
59 private static class Request {
61 @SuppressWarnings("unused")
62 private String action;
64 @SuppressWarnings("unused")
65 private Map<String, String> params;
68 this.action = "getFirmware";
69 this.params = new HashMap<>();
74 * Bridge Communication Structure containing the version of the firmware.
76 * Used within structure {@link JCgetFirmware} to describe the software of the Bridge.
78 private static class BCfirmwareVersion {
80 * "version": "0.1.1.0.41.0"
82 private String version = VeluxBindingConstants.UNKNOWN;
86 * Bridge I/O Response message used by {@link org.openhab.binding.velux.internal.bridge.json.JsonVeluxBridge} for
87 * deserializing with including component access methods
89 * Expected JSON (sample):
93 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
95 * "deviceStatus":"IDLE",
96 * "data":{"version":"0.1.1.0.41.0"},
101 private static class Response {
102 @SuppressWarnings("unused")
103 private String token = VeluxBindingConstants.UNKNOWN;
104 private boolean result;
105 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
106 private BCfirmwareVersion data = new BCfirmwareVersion();
107 private String[] errors = {};
111 * Methods required for interface {@link BridgeCommunicationProtocol}.
115 public String name() {
120 public String getURL() {
125 public Object getObjectOfRequest() {
130 public Class<Response> getClassOfResponse() {
131 return Response.class;
135 public void setResponse(Object thisResponse) {
136 response = (Response) thisResponse;
140 public boolean isCommunicationSuccessful() {
141 return response.result;
145 public String getDeviceStatus() {
146 return response.deviceStatus;
150 public String[] getErrors() {
151 return response.errors;
155 * Methods in addition to interface {@link JsonBridgeCommunicationProtocol}.
158 public VeluxGwFirmware getFirmware() {
159 return new VeluxGwFirmware(response.data.version);