]> git.basschouten.com Git - openhab-addons.git/blob
5bf237e34ffbf38a48f9cd4aeceade7a3eb752f2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.velux.internal.bridge.json;
14
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.SetSceneVelocity;
19
20 /**
21  * Specific bridge communication message supported by the Velux bridge.
22  * <P>
23  * Message semantic: setting of scene silent mode, resulting in a return of current bridge state.
24  * <P>
25  *
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 org.openhab.binding.velux.internal.bridge.json.JsonBridgeCommunicationProtocol
29  * BridgeCommunicationProtocol}.
30  *
31  * @author Guenther Schreiner - Initial contribution.
32  */
33 @Deprecated
34 @NonNullByDefault
35 class JCsetSceneVelocity extends SetSceneVelocity implements JsonBridgeCommunicationProtocol {
36
37     private static final String URL = "/api/v1/scenes";
38     private static final String DESCRIPTION = "modify silent mode";
39
40     private Request request = new Request();
41     private Response response = new Response();
42
43     private static int productId;
44     private static boolean silentMode;
45
46     /*
47      * Message Objects
48      */
49     private static class ParamsRunScene {
50         @SuppressWarnings("unused")
51         private int id;
52         @SuppressWarnings("unused")
53         private boolean silent;
54
55         private ParamsRunScene(int id, boolean silent) {
56             this.id = id;
57             this.silent = silent;
58         }
59     }
60
61     /**
62      * Bridge I/O Request message used by {@link JsonVeluxBridge}
63      * for serializing.
64      * <P>
65      * Resulting JSON (sample):
66      *
67      * <pre>
68      * {"action":"setSilentMode","params":{"id":9,"silent":false}}}
69      * </pre>
70      */
71     private static class Request {
72         @SuppressWarnings("unused")
73         private String action;
74         @SuppressWarnings("unused")
75         private ParamsRunScene params;
76
77         public Request() {
78             this.action = "setSilentMode";
79             this.params = new ParamsRunScene(JCsetSceneVelocity.productId, JCsetSceneVelocity.silentMode);
80         }
81     }
82
83     /**
84      * Bridge I/O Response message used by {@link JsonVeluxBridge} for deserializing with including component access
85      * methods
86      * <P>
87      * Expected JSON (sample):
88      *
89      * <pre>
90      * {
91      *  "token":"RHIKGlJyZhidI/JSK0a2RQ==",
92      *  "result":true,
93      *  "deviceStatus":"IDLE",
94      *  "data":{},
95      *  "errors":[]
96      * }
97      * </pre>
98      */
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 = {};
107
108         public boolean getResult() {
109             return result;
110         }
111     }
112
113     /*
114      * Methods required for interface {@link BridgeCommunicationProtocol}.
115      */
116
117     @Override
118     public String name() {
119         return DESCRIPTION;
120     }
121
122     @Override
123     public String getURL() {
124         return URL;
125     }
126
127     @Override
128     public Object getObjectOfRequest() {
129         return request;
130     }
131
132     @Override
133     public Class<Response> getClassOfResponse() {
134         return Response.class;
135     }
136
137     @Override
138     public void setResponse(Object response) {
139         this.response = (Response) response;
140     }
141
142     @Override
143     public boolean isCommunicationSuccessful() {
144         return response.getResult();
145     }
146
147     @Override
148     public String getDeviceStatus() {
149         return response.deviceStatus;
150     }
151
152     @Override
153     public String[] getErrors() {
154         return response.errors;
155     }
156
157     /*
158      * Methods in addition to interface {@link BridgeCommunicationProtocol}.
159      */
160     @Override
161     public JCsetSceneVelocity setMode(int id, boolean silent) {
162         JCsetSceneVelocity.productId = id;
163         JCsetSceneVelocity.silentMode = silent;
164         return this;
165     }
166 }