2 * Copyright (c) 2010-2022 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.elroconnects.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.elroconnects.internal.util.ElroConnectsUtil;
19 import com.google.gson.annotations.SerializedName;
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.
25 * @author Mark Herwege - Initial contribution
27 @SuppressWarnings("unused") // Suppress warning on serialized fields
29 public class ElroConnectsMessage {
31 private static class Data {
34 @SerializedName(value = "device_ID")
35 private @Nullable Integer deviceId;
37 @SerializedName(value = "device_name")
38 private @Nullable String deviceName;
40 @SerializedName(value = "device_status")
41 private @Nullable String deviceStatus;
43 @SerializedName(value = "answer_content")
44 private @Nullable String answerContent;
46 @SerializedName(value = "sence_group")
47 private @Nullable Integer sceneGroup;
49 @SerializedName(value = "scene_type")
50 private @Nullable Integer sceneType;
52 @SerializedName(value = "scene_content")
53 private @Nullable String sceneContent;
56 private static class Params {
57 private String devTid = "";
58 private String ctrlKey = "";
59 private Data data = new Data();
63 private String action = "appSend";
64 private Params params = new Params();
66 public ElroConnectsMessage(int msgId, String devTid, String ctrlKey, int cmdId) {
68 params.devTid = devTid;
69 params.ctrlKey = ctrlKey;
70 params.data.cmdId = cmdId;
73 public ElroConnectsMessage(int msgId) {
78 public ElroConnectsMessage withDeviceStatus(String deviceStatus) {
79 params.data.deviceStatus = deviceStatus;
83 public ElroConnectsMessage withDeviceId(int deviceId) {
84 params.data.deviceId = deviceId;
88 public ElroConnectsMessage withSceneType(int sceneType) {
89 params.data.sceneType = sceneType;
93 public ElroConnectsMessage withSceneGroup(int sceneGroup) {
94 params.data.sceneGroup = sceneGroup;
98 public ElroConnectsMessage withSceneContent(String sceneContent) {
99 params.data.sceneContent = sceneContent;
103 public ElroConnectsMessage withAnswerContent(String answerContent) {
104 params.data.answerContent = answerContent;
108 public int getMsgId() {
112 public String getAction() {
116 public int getCmdId() {
117 return params.data.cmdId;
120 public String getDeviceStatus() {
121 return ElroConnectsUtil.stringOrEmpty(params.data.deviceStatus);
124 public int getSceneGroup() {
125 return ElroConnectsUtil.intOrZero(params.data.sceneGroup);
128 public int getSceneType() {
129 return ElroConnectsUtil.intOrZero(params.data.sceneType);
132 public String getSceneContent() {
133 return ElroConnectsUtil.stringOrEmpty(params.data.sceneContent);
136 public String getAnswerContent() {
137 return ElroConnectsUtil.stringOrEmpty(params.data.answerContent);
140 public int getDeviceId() {
141 return ElroConnectsUtil.intOrZero(params.data.deviceId);
144 public String getDeviceName() {
145 return ElroConnectsUtil.stringOrEmpty(params.data.deviceName);