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 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;
49 private static class ParamsIdentifyProduct {
50 @SuppressWarnings("unused")
52 @SuppressWarnings("unused")
55 private ParamsIdentifyProduct(int id, int time) {
62 * Bridge I/O Request message used by {@link JsonVeluxBridge} for serializing.
64 * Resulting JSON (sample):
67 * {"action":"identify","params":{"id":23,"time":254}}
70 private static class Request {
71 @SuppressWarnings("unused")
72 private String action;
73 @SuppressWarnings("unused")
74 private ParamsIdentifyProduct params;
77 this.action = "identify";
78 this.params = new ParamsIdentifyProduct(JCrunProductIdentification.productId,
79 JCrunProductIdentification.identifyTime);
84 * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
87 * Expected JSON (sample):
91 * "token": "NkR/AA5xXj7iL6NiIW8keA==",
93 * "deviceStatus": "IDLE",
99 private static class Response {
100 @SuppressWarnings("unused")
101 private String token = VeluxBindingConstants.UNKNOWN;
102 private boolean result;
103 private String deviceStatus = VeluxBindingConstants.UNKNOWN;
104 @SuppressWarnings("unused")
105 private @Nullable Object data;
106 private String[] errors = {};
108 public boolean getResult() {
112 public String getDeviceStatus() {
116 public String[] getErrors() {
122 * Methods required for interface {@link BridgeCommunicationProtocol}.
126 public String name() {
131 public String getURL() {
136 public Object getObjectOfRequest() {
141 public Class<Response> getClassOfResponse() {
142 return Response.class;
146 public void setResponse(Object response) {
147 this.response = (Response) response;
151 public boolean isCommunicationSuccessful() {
152 return response.getResult();
156 public String getDeviceStatus() {
157 return response.getDeviceStatus();
161 public String[] getErrors() {
162 return response.getErrors();
166 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
169 public JCrunProductIdentification setProductId(int id) {
170 JCrunProductIdentification.productId = id;