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.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.velux.internal.VeluxBindingConstants;
21 import org.openhab.binding.velux.internal.bridge.common.RunProductDiscovery;
24 * Specific bridge communication message supported by the Velux bridge.
26 * Message semantic:Action to start discovery of products, i.e. Velux devices.
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 JsonBridgeCommunicationProtocol}.
33 * @author Guenther Schreiner - Initial contribution.
36 class JCrunProductDiscovery extends RunProductDiscovery implements JsonBridgeCommunicationProtocol {
38 private static final String URL = "/api/v1/products";
39 private static final String DESCRIPTION = "discover products";
41 private Request request = new Request();
42 private Response response = new Response();
49 * Bridge I/O Request message used by {@link JsonVeluxBridge}
55 * {"action":"discover","params":{}}
58 * NOTE: the gateway software is extremely sensitive to this exact JSON structure.
59 * Any modifications (like omitting empty params) will lead to a gateway error.
61 private static class Request {
63 @SuppressWarnings("unused")
64 private String action;
66 @SuppressWarnings("unused")
67 private Map<String, String> params;
70 this.action = "discover";
71 this.params = new HashMap<>();
76 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
79 * Expected JSON (sample):
83 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
85 * "deviceStatus":"discovering",
91 private static class Response {
92 @SuppressWarnings("unused")
93 private String token = VeluxBindingConstants.UNKNOWN;
94 private boolean result;
95 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
96 @SuppressWarnings("unused")
97 private @Nullable Object data = null;
98 private String[] errors = {};
100 public boolean getResult() {
104 public String getDeviceStatus() {
108 public String[] getErrors() {
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.getResult();
148 public String getDeviceStatus() {
149 return response.getDeviceStatus();
153 public String[] getErrors() {
154 return response.getErrors();