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.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 an gateway error.
62 private static class Request {
64 @SuppressWarnings("unused")
65 private String action;
67 @SuppressWarnings("unused")
68 private Map<String, String> params;
71 this.action = "discover";
72 this.params = new HashMap<>();
77 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
80 * Expected JSON (sample):
84 * "token":"RHIKGlJyZhidI/JSK0a2RQ==",
86 * "deviceStatus":"discovering",
93 private static class Response {
94 @SuppressWarnings("unused")
95 private String token = VeluxBindingConstants.UNKNOWN;
96 private boolean result;
97 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
98 @SuppressWarnings("unused")
99 private @Nullable Object data = null;
100 private String[] errors = {};
102 public boolean getResult() {
106 public String getDeviceStatus() {
110 public String[] getErrors() {
116 * Methods required for interface {@link BridgeCommunicationProtocol}.
120 public String name() {
125 public String getURL() {
130 public Object getObjectOfRequest() {
135 public Class<Response> getClassOfResponse() {
136 return Response.class;
140 public void setResponse(Object thisResponse) {
141 response = (Response) thisResponse;
145 public boolean isCommunicationSuccessful() {
146 return response.getResult();
150 public String getDeviceStatus() {
151 return response.getDeviceStatus();
155 public String[] getErrors() {
156 return response.getErrors();