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