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