2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.miio.internal.basic;
15 import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID;
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.LinkedHashSet;
20 import java.util.List;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
25 import com.google.gson.annotations.Expose;
26 import com.google.gson.annotations.SerializedName;
29 * Mapping properties from json
31 * @author Marcel Verpaalen - Initial contribution
34 public class MiIoBasicChannel {
36 @SerializedName("property")
38 private @Nullable String property;
39 @SerializedName("siid")
41 private @Nullable Integer siid;
42 @SerializedName("piid")
44 private @Nullable Integer piid;
45 @SerializedName("friendlyName")
47 private @Nullable String friendlyName;
48 @SerializedName("channel")
50 private @Nullable String channel;
51 @SerializedName("description")
53 private @Nullable String description;
54 @SerializedName("channelType")
56 private @Nullable String channelType;
57 @SerializedName("type")
59 private @Nullable String type;
60 @SerializedName("unit")
62 private @Nullable String unit;
63 @SerializedName("stateDescription")
65 private @Nullable StateDescriptionDTO stateDescription;
66 @SerializedName("refresh")
68 private @Nullable Boolean refresh;
69 @SerializedName("customRefreshCommand")
71 private @Nullable String channelCustomRefreshCommand;
72 @SerializedName("transformation")
74 private @Nullable String transformation;
75 @SerializedName("ChannelGroup")
77 private @Nullable String channelGroup;
78 @SerializedName("actions")
80 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
81 @SerializedName("category")
83 private @Nullable String category;
84 @SerializedName("tags")
86 private @Nullable LinkedHashSet<String> tags;
87 @SerializedName("readmeComment")
89 private @Nullable String readmeComment;
91 public String getProperty() {
92 final String property = this.property;
93 return (property != null) ? property : "";
96 public void setProperty(@Nullable String property) {
97 this.property = property;
100 public int getSiid() {
101 final Integer siid = this.siid;
103 return siid.intValue();
109 public void setSiid(@Nullable Integer siid) {
113 public int getPiid() {
114 final Integer piid = this.piid;
116 return piid.intValue();
122 public void setPiid(@Nullable Integer piid) {
126 public boolean isMiOt() {
127 return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
130 public String getFriendlyName() {
131 final String fn = friendlyName;
132 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
135 public void setFriendlyName(@Nullable String friendlyName) {
136 this.friendlyName = friendlyName;
139 public String getChannel() {
140 final @Nullable String channel = this.channel;
141 return channel != null ? channel : "";
144 public void setChannel(@Nullable String channel) {
145 this.channel = channel;
148 public String getDescription() {
149 final String description = this.description;
150 return description != null ? description : "";
153 public void setDescription(@Nullable String description) {
154 this.description = description;
157 public String getChannelType() {
158 final @Nullable String ct = channelType;
159 if (ct == null || ct.isEmpty()) {
162 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
166 public void setChannelType(@Nullable String channelType) {
167 this.channelType = channelType;
170 public String getType() {
171 final @Nullable String type = this.type;
172 return type != null ? type : "";
175 public void setType(@Nullable String type) {
179 public String getUnit() {
180 final @Nullable String unit = this.unit;
181 return unit != null ? unit : "";
184 public void setUnit(@Nullable String unit) {
188 public @Nullable StateDescriptionDTO getStateDescription() {
189 return stateDescription;
192 public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
193 this.stateDescription = stateDescription;
196 public Boolean getRefresh() {
197 final @Nullable Boolean rf = refresh;
198 return rf != null && rf.booleanValue();
201 public void setRefresh(@Nullable Boolean refresh) {
202 this.refresh = refresh;
205 public String getChannelCustomRefreshCommand() {
206 final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
207 return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
210 public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
211 this.channelCustomRefreshCommand = channelCustomRefreshCommand;
214 public String getChannelGroup() {
215 final @Nullable String channelGroup = this.channelGroup;
216 return channelGroup != null ? channelGroup : "";
219 public void setChannelGroup(@Nullable String channelGroup) {
220 this.channelGroup = channelGroup;
223 public List<MiIoDeviceAction> getActions() {
224 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
225 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
228 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
229 this.miIoDeviceActions = miIoDeviceActions;
232 public @Nullable String getTransformation() {
233 return transformation;
236 public void setTransformation(@Nullable String transformation) {
237 this.transformation = transformation;
240 public @Nullable String getCategory() {
244 public void setCategory(@Nullable String category) {
245 this.category = category;
248 public @Nullable LinkedHashSet<String> getTags() {
252 public void setTags(@Nullable LinkedHashSet<String> tags) {
256 public String getReadmeComment() {
257 final String readmeComment = this.readmeComment;
258 return (readmeComment != null) ? readmeComment : "";
261 public void setReadmeComment(@Nullable String readmeComment) {
262 this.readmeComment = readmeComment;
266 public String toString() {
267 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
268 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
269 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";