]> git.basschouten.com Git - openhab-addons.git/blob
9391acd15bdadfb70f4bc97813f777985fc3ba25
[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 transformation;
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         return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
125     }
126
127     public String getFriendlyName() {
128         final String fn = friendlyName;
129         return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
130     }
131
132     public void setFriendlyName(@Nullable String friendlyName) {
133         this.friendlyName = friendlyName;
134     }
135
136     public String getChannel() {
137         final @Nullable String channel = this.channel;
138         return channel != null ? channel : "";
139     }
140
141     public void setChannel(@Nullable String channel) {
142         this.channel = channel;
143     }
144
145     public String getChannelType() {
146         final @Nullable String ct = channelType;
147         if (ct == null || ct.isEmpty()) {
148             return "";
149         } else {
150             return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
151         }
152     }
153
154     public void setChannelType(@Nullable String channelType) {
155         this.channelType = channelType;
156     }
157
158     public String getType() {
159         final @Nullable String type = this.type;
160         return type != null ? type : "";
161     }
162
163     public void setType(@Nullable String type) {
164         this.type = type;
165     }
166
167     public String getUnit() {
168         final @Nullable String unit = this.unit;
169         return unit != null ? unit : "";
170     }
171
172     public void setUnit(@Nullable String unit) {
173         this.unit = unit;
174     }
175
176     public @Nullable StateDescriptionDTO getStateDescription() {
177         return stateDescription;
178     }
179
180     public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
181         this.stateDescription = stateDescription;
182     }
183
184     public Boolean getRefresh() {
185         final @Nullable Boolean rf = refresh;
186         return rf != null && rf.booleanValue();
187     }
188
189     public void setRefresh(@Nullable Boolean refresh) {
190         this.refresh = refresh;
191     }
192
193     public String getChannelCustomRefreshCommand() {
194         final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
195         return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
196     }
197
198     public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
199         this.channelCustomRefreshCommand = channelCustomRefreshCommand;
200     }
201
202     public String getChannelGroup() {
203         final @Nullable String channelGroup = this.channelGroup;
204         return channelGroup != null ? channelGroup : "";
205     }
206
207     public void setChannelGroup(@Nullable String channelGroup) {
208         this.channelGroup = channelGroup;
209     }
210
211     public List<MiIoDeviceAction> getActions() {
212         final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
213         return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
214     }
215
216     public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
217         this.miIoDeviceActions = miIoDeviceActions;
218     }
219
220     public @Nullable String getTransformation() {
221         return transformation;
222     }
223
224     public void setTransformation(@Nullable String transformation) {
225         this.transformation = transformation;
226     }
227
228     public @Nullable String getCategory() {
229         return category;
230     }
231
232     public void setCategory(@Nullable String category) {
233         this.category = category;
234     }
235
236     public @Nullable LinkedHashSet<String> getTags() {
237         return tags;
238     }
239
240     public void setTags(@Nullable LinkedHashSet<String> tags) {
241         this.tags = tags;
242     }
243
244     public String getReadmeComment() {
245         final String readmeComment = this.readmeComment;
246         return (readmeComment != null) ? readmeComment : "";
247     }
248
249     public void setReadmeComment(@Nullable String readmeComment) {
250         this.readmeComment = readmeComment;
251     }
252
253     @Override
254     public String toString() {
255         return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
256                 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
257                 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";
258     }
259 }