2 * Copyright (c) 2010-2020 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.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
24 import com.google.gson.annotations.Expose;
25 import com.google.gson.annotations.SerializedName;
28 * Mapping properties from json
30 * @author Marcel Verpaalen - Initial contribution
33 public class MiIoBasicChannel {
35 @SerializedName("property")
37 private @Nullable String property;
38 @SerializedName("siid")
40 private @Nullable Integer siid;
41 @SerializedName("piid")
43 private @Nullable Integer piid;
44 @SerializedName("friendlyName")
46 private @Nullable String friendlyName;
47 @SerializedName("channel")
49 private @Nullable String channel;
50 @SerializedName("channelType")
52 private @Nullable String channelType;
53 @SerializedName("type")
55 private @Nullable String type;
56 @SerializedName("unit")
58 private @Nullable String unit;
59 @SerializedName("refresh")
61 private @Nullable Boolean refresh;
62 @SerializedName("customRefreshCommand")
64 private @Nullable String channelCustomRefreshCommand;
65 @SerializedName("transformation")
67 private @Nullable String transfortmation;
68 @SerializedName("ChannelGroup")
70 private @Nullable String channelGroup;
71 @SerializedName("actions")
73 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
74 @SerializedName("readmeComment")
76 private @Nullable String readmeComment;
78 public String getProperty() {
79 final String property = this.property;
80 return (property != null) ? property : "";
83 public void setProperty(String property) {
84 this.property = property;
87 public int getSiid() {
88 final Integer siid = this.siid;
90 return siid.intValue();
96 public void setSiid(Integer siid) {
100 public int getPiid() {
101 final Integer piid = this.piid;
103 return piid.intValue();
109 public void setPiid(Integer piid) {
113 public boolean isMiOt() {
114 if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
121 public String getFriendlyName() {
122 final String fn = friendlyName;
123 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
126 public void setFriendlyName(String friendlyName) {
127 this.friendlyName = friendlyName;
130 public String getChannel() {
131 final @Nullable String channel = this.channel;
132 return channel != null ? channel : "";
135 public void setChannel(String channel) {
136 this.channel = channel;
139 public String getChannelType() {
140 final @Nullable String ct = channelType;
141 if (ct == null || ct.isEmpty()) {
144 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
148 public void setChannelType(String channelType) {
149 this.channelType = channelType;
152 public String getType() {
153 final @Nullable String type = this.type;
154 return type != null ? type : "";
157 public void setType(String type) {
161 public String getUnit() {
162 final @Nullable String unit = this.unit;
163 return unit != null ? unit : "";
166 public void setUnit(String unit) {
170 public Boolean getRefresh() {
171 final @Nullable Boolean rf = refresh;
172 return rf != null && rf.booleanValue() && !getProperty().isEmpty();
175 public void setRefresh(Boolean refresh) {
176 this.refresh = refresh;
179 public String getChannelCustomRefreshCommand() {
180 final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
181 return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
184 public void setChannelCustomRefreshCommand(String channelCustomRefreshCommand) {
185 this.channelCustomRefreshCommand = channelCustomRefreshCommand;
188 public String getChannelGroup() {
189 final @Nullable String channelGroup = this.channelGroup;
190 return channelGroup != null ? channelGroup : "";
193 public void setChannelGroup(String channelGroup) {
194 this.channelGroup = channelGroup;
197 public List<MiIoDeviceAction> getActions() {
198 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
199 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
202 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
203 this.miIoDeviceActions = miIoDeviceActions;
206 public @Nullable String getTransfortmation() {
207 return transfortmation;
210 public void setTransfortmation(String transfortmation) {
211 this.transfortmation = transfortmation;
214 public String getReadmeComment() {
215 final String readmeComment = this.readmeComment;
216 return (readmeComment != null) ? readmeComment : "";
219 public void setReadmeComment(String readmeComment) {
220 this.readmeComment = readmeComment;
224 public String toString() {
225 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
226 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
227 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";