]> git.basschouten.com Git - openhab-addons.git/blob
ac7ddea8760e46ba46fa07495e271b946cfb06ad
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.elroconnects.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.elroconnects.internal.util.ElroConnectsUtil;
18
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * The {@link ElroConnectsMessage} represents the JSON messages exchanged with the ELRO Connects K1 Connector. This
23  * class is used to serialize/deserialize the messages.
24  *
25  * @author Mark Herwege - Initial contribution
26  */
27 @SuppressWarnings("unused") // Suppress warning on serialized fields
28 @NonNullByDefault
29 public class ElroConnectsMessage {
30
31     private static class Data {
32         private int cmdId;
33
34         @SerializedName(value = "device_ID")
35         private @Nullable Integer deviceId;
36
37         @SerializedName(value = "device_name")
38         private @Nullable String deviceName;
39
40         @SerializedName(value = "device_status")
41         private @Nullable String deviceStatus;
42
43         @SerializedName(value = "answer_content")
44         private @Nullable String answerContent;
45
46         @SerializedName(value = "sence_group")
47         private @Nullable Integer sceneGroup;
48
49         @SerializedName(value = "scene_type")
50         private @Nullable Integer sceneType;
51
52         @SerializedName(value = "scene_content")
53         private @Nullable String sceneContent;
54     }
55
56     private static class Params {
57         private String devTid = "";
58         private String ctrlKey = "";
59         private Data data = new Data();
60     }
61
62     private int msgId;
63     private String action = "appSend";
64     private Params params = new Params();
65
66     public ElroConnectsMessage(int msgId, String devTid, String ctrlKey, int cmdId) {
67         this.msgId = msgId;
68         params.devTid = devTid;
69         params.ctrlKey = ctrlKey;
70         params.data.cmdId = cmdId;
71     }
72
73     public ElroConnectsMessage(int msgId) {
74         this.msgId = msgId;
75         action = "heartbeat";
76     }
77
78     public ElroConnectsMessage withDeviceStatus(String deviceStatus) {
79         params.data.deviceStatus = deviceStatus;
80         return this;
81     }
82
83     public ElroConnectsMessage withDeviceId(int deviceId) {
84         params.data.deviceId = deviceId;
85         return this;
86     }
87
88     public ElroConnectsMessage withSceneType(int sceneType) {
89         params.data.sceneType = sceneType;
90         return this;
91     }
92
93     public ElroConnectsMessage withSceneGroup(int sceneGroup) {
94         params.data.sceneGroup = sceneGroup;
95         return this;
96     }
97
98     public ElroConnectsMessage withSceneContent(String sceneContent) {
99         params.data.sceneContent = sceneContent;
100         return this;
101     }
102
103     public ElroConnectsMessage withAnswerContent(String answerContent) {
104         params.data.answerContent = answerContent;
105         return this;
106     }
107
108     public int getMsgId() {
109         return msgId;
110     }
111
112     public String getAction() {
113         return action;
114     }
115
116     public int getCmdId() {
117         return params.data.cmdId;
118     }
119
120     public String getDeviceStatus() {
121         return ElroConnectsUtil.stringOrEmpty(params.data.deviceStatus);
122     }
123
124     public int getSceneGroup() {
125         return ElroConnectsUtil.intOrZero(params.data.sceneGroup);
126     }
127
128     public int getSceneType() {
129         return ElroConnectsUtil.intOrZero(params.data.sceneType);
130     }
131
132     public String getSceneContent() {
133         return ElroConnectsUtil.stringOrEmpty(params.data.sceneContent);
134     }
135
136     public String getAnswerContent() {
137         return ElroConnectsUtil.stringOrEmpty(params.data.answerContent);
138     }
139
140     public int getDeviceId() {
141         return ElroConnectsUtil.intOrZero(params.data.deviceId);
142     }
143
144     public String getDeviceName() {
145         return ElroConnectsUtil.stringOrEmpty(params.data.deviceName);
146     }
147 }