]> git.basschouten.com Git - openhab-addons.git/blob
4374cbbbb262824590e79bed4c9249077299c78a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID;
16
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.LinkedHashSet;
20 import java.util.List;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24
25 import com.google.gson.annotations.Expose;
26 import com.google.gson.annotations.SerializedName;
27
28 /**
29  * Mapping properties from json
30  *
31  * @author Marcel Verpaalen - Initial contribution
32  */
33 @NonNullByDefault
34 public class MiIoBasicChannel {
35
36     @SerializedName("property")
37     @Expose
38     private @Nullable String property;
39     @SerializedName("siid")
40     @Expose
41     private @Nullable Integer siid;
42     @SerializedName("piid")
43     @Expose
44     private @Nullable Integer piid;
45     @SerializedName("friendlyName")
46     @Expose
47     private @Nullable String friendlyName;
48     @SerializedName("channel")
49     @Expose
50     private @Nullable String channel;
51     @SerializedName("channelType")
52     @Expose
53     private @Nullable String channelType;
54     @SerializedName("type")
55     @Expose
56     private @Nullable String type;
57     @SerializedName("unit")
58     @Expose
59     private @Nullable String unit;
60     @SerializedName("stateDescription")
61     @Expose
62     private @Nullable StateDescriptionDTO stateDescription;
63     @SerializedName("refresh")
64     @Expose
65     private @Nullable Boolean refresh;
66     @SerializedName("customRefreshCommand")
67     @Expose
68     private @Nullable String channelCustomRefreshCommand;
69     @SerializedName("transformation")
70     @Expose
71     private @Nullable String transfortmation;
72     @SerializedName("ChannelGroup")
73     @Expose
74     private @Nullable String channelGroup;
75     @SerializedName("actions")
76     @Expose
77     private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
78     @SerializedName("category")
79     @Expose
80     private @Nullable String category;
81     @SerializedName("tags")
82     @Expose
83     private @Nullable LinkedHashSet<String> tags;
84     @SerializedName("readmeComment")
85     @Expose
86     private @Nullable String readmeComment;
87
88     public String getProperty() {
89         final String property = this.property;
90         return (property != null) ? property : "";
91     }
92
93     public void setProperty(@Nullable String property) {
94         this.property = property;
95     }
96
97     public int getSiid() {
98         final Integer siid = this.siid;
99         if (siid != null) {
100             return siid.intValue();
101         } else {
102             return 0;
103         }
104     }
105
106     public void setSiid(@Nullable Integer siid) {
107         this.siid = siid;
108     }
109
110     public int getPiid() {
111         final Integer piid = this.piid;
112         if (piid != null) {
113             return piid.intValue();
114         } else {
115             return 0;
116         }
117     }
118
119     public void setPiid(@Nullable Integer piid) {
120         this.piid = piid;
121     }
122
123     public boolean isMiOt() {
124         if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
125             return true;
126         } else {
127             return false;
128         }
129     }
130
131     public String getFriendlyName() {
132         final String fn = friendlyName;
133         return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
134     }
135
136     public void setFriendlyName(@Nullable String friendlyName) {
137         this.friendlyName = friendlyName;
138     }
139
140     public String getChannel() {
141         final @Nullable String channel = this.channel;
142         return channel != null ? channel : "";
143     }
144
145     public void setChannel(@Nullable String channel) {
146         this.channel = channel;
147     }
148
149     public String getChannelType() {
150         final @Nullable String ct = channelType;
151         if (ct == null || ct.isEmpty()) {
152             return "";
153         } else {
154             return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
155         }
156     }
157
158     public void setChannelType(@Nullable String channelType) {
159         this.channelType = channelType;
160     }
161
162     public String getType() {
163         final @Nullable String type = this.type;
164         return type != null ? type : "";
165     }
166
167     public void setType(@Nullable String type) {
168         this.type = type;
169     }
170
171     public String getUnit() {
172         final @Nullable String unit = this.unit;
173         return unit != null ? unit : "";
174     }
175
176     public void setUnit(@Nullable String unit) {
177         this.unit = unit;
178     }
179
180     public @Nullable StateDescriptionDTO getStateDescription() {
181         return stateDescription;
182     }
183
184     public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
185         this.stateDescription = stateDescription;
186     }
187
188     public Boolean getRefresh() {
189         final @Nullable Boolean rf = refresh;
190         return rf != null && rf.booleanValue() && !getProperty().isEmpty();
191     }
192
193     public void setRefresh(@Nullable Boolean refresh) {
194         this.refresh = refresh;
195     }
196
197     public String getChannelCustomRefreshCommand() {
198         final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
199         return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
200     }
201
202     public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
203         this.channelCustomRefreshCommand = channelCustomRefreshCommand;
204     }
205
206     public String getChannelGroup() {
207         final @Nullable String channelGroup = this.channelGroup;
208         return channelGroup != null ? channelGroup : "";
209     }
210
211     public void setChannelGroup(@Nullable String channelGroup) {
212         this.channelGroup = channelGroup;
213     }
214
215     public List<MiIoDeviceAction> getActions() {
216         final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
217         return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
218     }
219
220     public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
221         this.miIoDeviceActions = miIoDeviceActions;
222     }
223
224     public @Nullable String getTransfortmation() {
225         return transfortmation;
226     }
227
228     public void setTransfortmation(@Nullable String transfortmation) {
229         this.transfortmation = transfortmation;
230     }
231
232     public @Nullable String getCategory() {
233         return category;
234     }
235
236     public void setCategory(@Nullable String category) {
237         this.category = category;
238     }
239
240     public @Nullable LinkedHashSet<String> getTags() {
241         return tags;
242     }
243
244     public void setTags(@Nullable LinkedHashSet<String> tags) {
245         this.tags = tags;
246     }
247
248     public String getReadmeComment() {
249         final String readmeComment = this.readmeComment;
250         return (readmeComment != null) ? readmeComment : "";
251     }
252
253     public void setReadmeComment(@Nullable String readmeComment) {
254         this.readmeComment = readmeComment;
255     }
256
257     @Override
258     public String toString() {
259         return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
260                 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
261                 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";
262     }
263 }