]> git.basschouten.com Git - openhab-addons.git/blob
27b1bf52dae4ae7a47401aa12401362011abb9ec
[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("refresh")
57     @Expose
58     private @Nullable Boolean refresh;
59     @SerializedName("customRefreshCommand")
60     @Expose
61     private @Nullable String channelCustomRefreshCommand;
62     @SerializedName("transformation")
63     @Expose
64     private @Nullable String transfortmation;
65     @SerializedName("ChannelGroup")
66     @Expose
67     private @Nullable String channelGroup;
68     @SerializedName("actions")
69     @Expose
70     private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
71     @SerializedName("readmeComment")
72     @Expose
73     private @Nullable String readmeComment;
74
75     public String getProperty() {
76         final String property = this.property;
77         return (property != null) ? property : "";
78     }
79
80     public void setProperty(String property) {
81         this.property = property;
82     }
83
84     public int getSiid() {
85         final Integer siid = this.siid;
86         if (siid != null) {
87             return siid.intValue();
88         } else {
89             return 0;
90         }
91     }
92
93     public void setSiid(Integer siid) {
94         this.siid = siid;
95     }
96
97     public int getPiid() {
98         final Integer piid = this.piid;
99         if (piid != null) {
100             return piid.intValue();
101         } else {
102             return 0;
103         }
104     }
105
106     public void setPiid(Integer piid) {
107         this.piid = piid;
108     }
109
110     public boolean isMiOt() {
111         if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
112             return true;
113         } else {
114             return false;
115         }
116     }
117
118     public String getFriendlyName() {
119         final String fn = friendlyName;
120         return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
121     }
122
123     public void setFriendlyName(String friendlyName) {
124         this.friendlyName = friendlyName;
125     }
126
127     public String getChannel() {
128         final @Nullable String channel = this.channel;
129         return channel != null ? channel : "";
130     }
131
132     public void setChannel(String channel) {
133         this.channel = channel;
134     }
135
136     public String getChannelType() {
137         final @Nullable String ct = channelType;
138         if (ct == null || ct.isEmpty()) {
139             return "";
140         } else {
141             return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
142         }
143     }
144
145     public void setChannelType(String channelType) {
146         this.channelType = channelType;
147     }
148
149     public String getType() {
150         final @Nullable String type = this.type;
151         return type != null ? type : "";
152     }
153
154     public void setType(String type) {
155         this.type = type;
156     }
157
158     public Boolean getRefresh() {
159         final @Nullable Boolean rf = refresh;
160         return rf != null && rf.booleanValue() && !getProperty().isEmpty();
161     }
162
163     public void setRefresh(Boolean refresh) {
164         this.refresh = refresh;
165     }
166
167     public String getChannelCustomRefreshCommand() {
168         final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
169         return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
170     }
171
172     public void setChannelCustomRefreshCommand(String channelCustomRefreshCommand) {
173         this.channelCustomRefreshCommand = channelCustomRefreshCommand;
174     }
175
176     public String getChannelGroup() {
177         final @Nullable String channelGroup = this.channelGroup;
178         return channelGroup != null ? channelGroup : "";
179     }
180
181     public void setChannelGroup(String channelGroup) {
182         this.channelGroup = channelGroup;
183     }
184
185     public List<MiIoDeviceAction> getActions() {
186         final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
187         return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
188     }
189
190     public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
191         this.miIoDeviceActions = miIoDeviceActions;
192     }
193
194     public @Nullable String getTransfortmation() {
195         return transfortmation;
196     }
197
198     public void setTransfortmation(String transfortmation) {
199         this.transfortmation = transfortmation;
200     }
201
202     public String getReadmeComment() {
203         final String readmeComment = this.readmeComment;
204         return (readmeComment != null) ? readmeComment : "";
205     }
206
207     public void setReadmeComment(String readmeComment) {
208         this.readmeComment = readmeComment;
209     }
210
211     @Override
212     public String toString() {
213         return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
214                 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
215                 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";
216     }
217 }