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.RunProductIdentification;
21 * Specific bridge communication message supported by the Velux bridge.
23 * Message semantic: Trigger action to identify a product, resulting in a return of current bridge state.
26 * It defines information how to send query and receive answer through the
27 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
28 * as described by the {@link JsonBridgeCommunicationProtocol}.
30 * @author Guenther Schreiner - Initial contribution.
34 class JCrunProductIdentification extends RunProductIdentification implements JsonBridgeCommunicationProtocol {
35 private static final int DEFAULT_IDENTIFY_TIME = 50;
37 private static final String URL = "/api/v1/products";
38 private static final String DESCRIPTION = "identify one product";
40 private Request request = new Request();
41 private Response response = new Response();
43 private static int productId;
44 private static int identifyTime = DEFAULT_IDENTIFY_TIME;
50 private static class ParamsIdentifyProduct {
51 @SuppressWarnings("unused")
53 @SuppressWarnings("unused")
56 private ParamsIdentifyProduct(int id, int time) {
63 * Bridge I/O Request message used by {@link JsonVeluxBridge} for serializing.
65 * Resulting JSON (sample):
68 * {"action":"identify","params":{"id":23,"time":254}}
72 private static class Request {
73 @SuppressWarnings("unused")
74 private String action;
75 @SuppressWarnings("unused")
76 private ParamsIdentifyProduct params;
79 this.action = "identify";
80 this.params = new ParamsIdentifyProduct(JCrunProductIdentification.productId,
81 JCrunProductIdentification.identifyTime);
86 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
89 * Expected JSON (sample):
93 * "token": "NkR/AA5xXj7iL6NiIW8keA==",
95 * "deviceStatus": "IDLE",
102 private static class Response {
103 @SuppressWarnings("unused")
104 private String token = VeluxBindingConstants.UNKNOWN;
105 private boolean result;
106 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
107 @SuppressWarnings("unused")
108 private @Nullable Object data;
109 private String[] errors = {};
111 public boolean getResult() {
115 public String getDeviceStatus() {
119 public String[] getErrors() {
125 * Methods required for interface {@link BridgeCommunicationProtocol}.
129 public String name() {
134 public String getURL() {
139 public Object getObjectOfRequest() {
144 public Class<Response> getClassOfResponse() {
145 return Response.class;
149 public void setResponse(Object response) {
150 this.response = (Response) response;
154 public boolean isCommunicationSuccessful() {
155 return response.getResult();
159 public String getDeviceStatus() {
160 return response.getDeviceStatus();
164 public String[] getErrors() {
165 return response.getErrors();
169 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
172 public JCrunProductIdentification setProductId(int id) {
173 JCrunProductIdentification.productId = id;