]> git.basschouten.com Git - openhab-addons.git/blob
33dc575743288bccb08520a5cadf3af6b81d046f
[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("description")
52     @Expose
53     private @Nullable String description;
54     @SerializedName("channelType")
55     @Expose
56     private @Nullable String channelType;
57     @SerializedName("type")
58     @Expose
59     private @Nullable String type;
60     @SerializedName("unit")
61     @Expose
62     private @Nullable String unit;
63     @SerializedName("stateDescription")
64     @Expose
65     private @Nullable StateDescriptionDTO stateDescription;
66     @SerializedName("refresh")
67     @Expose
68     private @Nullable Boolean refresh;
69     @SerializedName("customRefreshCommand")
70     @Expose
71     private @Nullable String channelCustomRefreshCommand;
72     @SerializedName("transformation")
73     @Expose
74     private @Nullable String transformation;
75     @SerializedName("ChannelGroup")
76     @Expose
77     private @Nullable String channelGroup;
78     @SerializedName("actions")
79     @Expose
80     private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
81     @SerializedName("category")
82     @Expose
83     private @Nullable String category;
84     @SerializedName("tags")
85     @Expose
86     private @Nullable LinkedHashSet<String> tags;
87     @SerializedName("readmeComment")
88     @Expose
89     private @Nullable String readmeComment;
90
91     public String getProperty() {
92         final String property = this.property;
93         return (property != null) ? property : "";
94     }
95
96     public void setProperty(@Nullable String property) {
97         this.property = property;
98     }
99
100     public int getSiid() {
101         final Integer siid = this.siid;
102         if (siid != null) {
103             return siid.intValue();
104         } else {
105             return 0;
106         }
107     }
108
109     public void setSiid(@Nullable Integer siid) {
110         this.siid = siid;
111     }
112
113     public int getPiid() {
114         final Integer piid = this.piid;
115         if (piid != null) {
116             return piid.intValue();
117         } else {
118             return 0;
119         }
120     }
121
122     public void setPiid(@Nullable Integer piid) {
123         this.piid = piid;
124     }
125
126     public boolean isMiOt() {
127         return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
128     }
129
130     public String getFriendlyName() {
131         final String fn = friendlyName;
132         return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
133     }
134
135     public void setFriendlyName(@Nullable String friendlyName) {
136         this.friendlyName = friendlyName;
137     }
138
139     public String getChannel() {
140         final @Nullable String channel = this.channel;
141         return channel != null ? channel : "";
142     }
143
144     public void setChannel(@Nullable String channel) {
145         this.channel = channel;
146     }
147
148     public String getDescription() {
149         final String description = this.description;
150         return description != null ? description : "";
151     }
152
153     public void setDescription(@Nullable String description) {
154         this.description = description;
155     }
156
157     public String getChannelType() {
158         final @Nullable String ct = channelType;
159         if (ct == null || ct.isEmpty()) {
160             return "";
161         } else {
162             return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
163         }
164     }
165
166     public void setChannelType(@Nullable String channelType) {
167         this.channelType = channelType;
168     }
169
170     public String getType() {
171         final @Nullable String type = this.type;
172         return type != null ? type : "";
173     }
174
175     public void setType(@Nullable String type) {
176         this.type = type;
177     }
178
179     public String getUnit() {
180         final @Nullable String unit = this.unit;
181         return unit != null ? unit : "";
182     }
183
184     public void setUnit(@Nullable String unit) {
185         this.unit = unit;
186     }
187
188     public @Nullable StateDescriptionDTO getStateDescription() {
189         return stateDescription;
190     }
191
192     public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
193         this.stateDescription = stateDescription;
194     }
195
196     public Boolean getRefresh() {
197         final @Nullable Boolean rf = refresh;
198         return rf != null && rf.booleanValue();
199     }
200
201     public void setRefresh(@Nullable Boolean refresh) {
202         this.refresh = refresh;
203     }
204
205     public String getChannelCustomRefreshCommand() {
206         final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
207         return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
208     }
209
210     public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
211         this.channelCustomRefreshCommand = channelCustomRefreshCommand;
212     }
213
214     public String getChannelGroup() {
215         final @Nullable String channelGroup = this.channelGroup;
216         return channelGroup != null ? channelGroup : "";
217     }
218
219     public void setChannelGroup(@Nullable String channelGroup) {
220         this.channelGroup = channelGroup;
221     }
222
223     public List<MiIoDeviceAction> getActions() {
224         final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
225         return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
226     }
227
228     public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
229         this.miIoDeviceActions = miIoDeviceActions;
230     }
231
232     public @Nullable String getTransformation() {
233         return transformation;
234     }
235
236     public void setTransformation(@Nullable String transformation) {
237         this.transformation = transformation;
238     }
239
240     public @Nullable String getCategory() {
241         return category;
242     }
243
244     public void setCategory(@Nullable String category) {
245         this.category = category;
246     }
247
248     public @Nullable LinkedHashSet<String> getTags() {
249         return tags;
250     }
251
252     public void setTags(@Nullable LinkedHashSet<String> tags) {
253         this.tags = tags;
254     }
255
256     public String getReadmeComment() {
257         final String readmeComment = this.readmeComment;
258         return (readmeComment != null) ? readmeComment : "";
259     }
260
261     public void setReadmeComment(@Nullable String readmeComment) {
262         this.readmeComment = readmeComment;
263     }
264
265     @Override
266     public String toString() {
267         return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
268                 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
269                 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";
270     }
271 }