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