]> git.basschouten.com Git - openhab-addons.git/blob
2bf8d88f7c35fdac4d61431a93bcf851e6769251
[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.miio.internal.basic;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 import com.google.gson.JsonArray;
19 import com.google.gson.annotations.Expose;
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * Mapping actions from json
24  *
25  * @author Marcel Verpaalen - Initial contribution
26  */
27 @NonNullByDefault
28 public class MiIoDeviceAction {
29
30     @SerializedName("command")
31     @Expose
32     private @Nullable String command;
33     @SerializedName("parameterType")
34     @Expose
35     private CommandParameterType commandParameterType = CommandParameterType.EMPTY;
36     @SerializedName("parameters")
37     @Expose
38     private @Nullable JsonArray parameters;
39     @SerializedName("siid")
40     @Expose
41     private @Nullable Integer siid;
42     @SerializedName("aiid")
43     @Expose
44     private @Nullable Integer aiid;
45     @SerializedName("condition")
46     @Expose
47     private @Nullable MiIoDeviceActionCondition condition;
48
49     public JsonArray getParameters() {
50         final @Nullable JsonArray parameter = this.parameters;
51         return parameter != null ? parameter : new JsonArray();
52     }
53
54     public void setParameters(JsonArray parameters) {
55         this.parameters = parameters;
56     }
57
58     public String getCommand() {
59         final @Nullable String command = this.command;
60         return command != null ? command : "";
61     }
62
63     public void setCommand(String command) {
64         this.command = command;
65     }
66
67     public CommandParameterType getparameterType() {
68         return commandParameterType;
69     }
70
71     public void setparameterType(CommandParameterType type) {
72         this.commandParameterType = type;
73     }
74
75     public void setparameterType(String type) {
76         this.commandParameterType = org.openhab.binding.miio.internal.basic.CommandParameterType.fromString(type);
77     }
78
79     public int getSiid() {
80         final Integer siid = this.siid;
81         if (siid != null) {
82             return siid.intValue();
83         } else {
84             return 0;
85         }
86     }
87
88     public void setSiid(Integer siid) {
89         this.siid = siid;
90     }
91
92     public int getAiid() {
93         final Integer aiid = this.aiid;
94         if (aiid != null) {
95             return aiid.intValue();
96         } else {
97             return 0;
98         }
99     }
100
101     public void setAiid(Integer aiid) {
102         this.aiid = aiid;
103     }
104
105     public boolean isMiOtAction() {
106         return aiid != null && siid != null && (getAiid() != 0 || getSiid() != 0);
107     }
108
109     public @Nullable MiIoDeviceActionCondition getCondition() {
110         return condition;
111     }
112
113     public void setCondition(@Nullable MiIoDeviceActionCondition condition) {
114         this.condition = condition;
115     }
116
117     @Override
118     public String toString() {
119         return "MiIoDeviceAction [command=" + command + ", commandParameterType=" + commandParameterType
120                 + (parameters != null ? ", parameters=" + getParameters().toString() : "") + "]";
121     }
122 }