]> git.basschouten.com Git - openhab-addons.git/blob
b348c193a7e15e90a9fe90323b090ec0caa0e078
[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 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.JsonElement;
26 import com.google.gson.annotations.Expose;
27 import com.google.gson.annotations.SerializedName;
28
29 /**
30  * Mapping properties from json
31  *
32  * @author Marcel Verpaalen - Initial contribution
33  */
34 @NonNullByDefault
35 public class MiIoBasicChannel {
36
37     @SerializedName("property")
38     @Expose
39     private @Nullable String property;
40     @SerializedName("siid")
41     @Expose
42     private @Nullable Integer siid;
43     @SerializedName("piid")
44     @Expose
45     private @Nullable Integer piid;
46     @SerializedName("friendlyName")
47     @Expose
48     private @Nullable String friendlyName;
49     @SerializedName("channel")
50     @Expose
51     private @Nullable String channel;
52     @SerializedName("description")
53     @Expose
54     private @Nullable String description;
55     @SerializedName("channelType")
56     @Expose
57     private @Nullable String channelType;
58     @SerializedName("type")
59     @Expose
60     private @Nullable String type;
61     @SerializedName("unit")
62     @Expose
63     private @Nullable String unit;
64     @SerializedName("stateDescription")
65     @Expose
66     private @Nullable StateDescriptionDTO stateDescription;
67     @SerializedName("refresh")
68     @Expose
69     private @Nullable Boolean refresh;
70     @SerializedName("refreshInterval")
71     @Expose
72     private @Nullable Integer refreshInterval;
73     @SerializedName("customRefreshCommand")
74     @Expose
75     private @Nullable String channelCustomRefreshCommand;
76     @SerializedName("customRefreshParameters")
77     @Expose
78     private @Nullable JsonElement customRefreshParameters;
79     @SerializedName("transformation")
80     @Expose
81     private @Nullable String transformation;
82     @SerializedName("transformations")
83     @Expose
84     private @Nullable List<String> transformations;
85     @SerializedName("ChannelGroup")
86     @Expose
87     private @Nullable String channelGroup;
88     @SerializedName("actions")
89     @Expose
90     private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
91     @SerializedName("category")
92     @Expose
93     private @Nullable String category;
94     @SerializedName("tags")
95     @Expose
96     private @Nullable LinkedHashSet<String> tags;
97     @SerializedName("readmeComment")
98     @Expose
99     private @Nullable String readmeComment;
100
101     public String getProperty() {
102         final String property = this.property;
103         return (property != null) ? property : "";
104     }
105
106     public void setProperty(@Nullable String property) {
107         this.property = property;
108     }
109
110     public int getSiid() {
111         final Integer siid = this.siid;
112         if (siid != null) {
113             return siid.intValue();
114         } else {
115             return 0;
116         }
117     }
118
119     public void setSiid(@Nullable Integer siid) {
120         this.siid = siid;
121     }
122
123     public int getPiid() {
124         final Integer piid = this.piid;
125         if (piid != null) {
126             return piid.intValue();
127         } else {
128             return 0;
129         }
130     }
131
132     public void setPiid(@Nullable Integer piid) {
133         this.piid = piid;
134     }
135
136     public boolean isMiOt() {
137         return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
138     }
139
140     public String getFriendlyName() {
141         final String fn = friendlyName;
142         return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
143     }
144
145     public void setFriendlyName(@Nullable String friendlyName) {
146         this.friendlyName = friendlyName;
147     }
148
149     public String getChannel() {
150         final @Nullable String channel = this.channel;
151         return channel != null ? channel : "";
152     }
153
154     public void setChannel(@Nullable String channel) {
155         this.channel = channel;
156     }
157
158     public String getDescription() {
159         final String description = this.description;
160         return description != null ? description : "";
161     }
162
163     public void setDescription(@Nullable String description) {
164         this.description = description;
165     }
166
167     public String getChannelType() {
168         final @Nullable String ct = channelType;
169         if (ct == null || ct.isEmpty()) {
170             return "";
171         } else {
172             return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
173         }
174     }
175
176     public void setChannelType(@Nullable String channelType) {
177         this.channelType = channelType;
178     }
179
180     public String getType() {
181         final @Nullable String type = this.type;
182         return type != null ? type : "";
183     }
184
185     public void setType(@Nullable String type) {
186         this.type = type;
187     }
188
189     public String getUnit() {
190         final @Nullable String unit = this.unit;
191         return unit != null ? unit : "";
192     }
193
194     public void setUnit(@Nullable String unit) {
195         this.unit = unit;
196     }
197
198     public @Nullable StateDescriptionDTO getStateDescription() {
199         return stateDescription;
200     }
201
202     public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
203         this.stateDescription = stateDescription;
204     }
205
206     public Boolean getRefresh() {
207         final @Nullable Boolean rf = refresh;
208         return rf != null && rf.booleanValue();
209     }
210
211     public void setRefresh(@Nullable Boolean refresh) {
212         this.refresh = refresh;
213     }
214
215     public Integer getRefreshInterval() {
216         Integer refreshInterval = this.refreshInterval;
217         if (refreshInterval != null) {
218             return refreshInterval;
219         }
220         return 1;
221     }
222
223     public void setRefresh(@Nullable final Integer interval) {
224         final Integer refreshInterval = interval;
225         if (refreshInterval != null && refreshInterval.intValue() != 1) {
226             this.refreshInterval = refreshInterval;
227         } else {
228             this.refreshInterval = null;
229         }
230     }
231
232     public String getChannelCustomRefreshCommand() {
233         final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
234         return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
235     }
236
237     public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
238         this.channelCustomRefreshCommand = channelCustomRefreshCommand;
239     }
240
241     public @Nullable final JsonElement getCustomRefreshParameters() {
242         return customRefreshParameters;
243     }
244
245     public final void setCustomRefreshParameters(@Nullable JsonElement customRefreshParameters) {
246         this.customRefreshParameters = customRefreshParameters;
247     }
248
249     public String getChannelGroup() {
250         final @Nullable String channelGroup = this.channelGroup;
251         return channelGroup != null ? channelGroup : "";
252     }
253
254     public void setChannelGroup(@Nullable String channelGroup) {
255         this.channelGroup = channelGroup;
256     }
257
258     public List<MiIoDeviceAction> getActions() {
259         final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
260         return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
261     }
262
263     public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
264         this.miIoDeviceActions = miIoDeviceActions;
265     }
266
267     public @Nullable String getTransformation() {
268         return transformation;
269     }
270
271     public void setTransformation(@Nullable String transformation) {
272         this.transformation = transformation;
273     }
274
275     public final List<String> getTransformations() {
276         List<String> transformations = this.transformations;
277         if (transformations == null) {
278             transformations = new ArrayList<>();
279         }
280         String transformation = this.transformation;
281         if (transformation != null) {
282             List<String> allTransformation = new ArrayList<>(List.of(transformation));
283             allTransformation.addAll(transformations);
284             return allTransformation;
285         }
286         return transformations;
287     }
288
289     public final void setTransformations(@Nullable List<String> transformations) {
290         if (transformations != null && !transformations.isEmpty()) {
291             this.transformations = transformations;
292         } else {
293             this.transformations = null;
294         }
295     }
296
297     public @Nullable String getCategory() {
298         return category;
299     }
300
301     public void setCategory(@Nullable String category) {
302         this.category = category;
303     }
304
305     public @Nullable LinkedHashSet<String> getTags() {
306         return tags;
307     }
308
309     public void setTags(@Nullable LinkedHashSet<String> tags) {
310         this.tags = tags;
311     }
312
313     public String getReadmeComment() {
314         final String readmeComment = this.readmeComment;
315         return (readmeComment != null) ? readmeComment : "";
316     }
317
318     public void setReadmeComment(@Nullable String readmeComment) {
319         this.readmeComment = readmeComment;
320     }
321
322     @Override
323     public String toString() {
324         return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
325                 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
326                 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";
327     }
328 }