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("refresh")
58 private @Nullable Boolean refresh;
59 @SerializedName("transformation")
61 private @Nullable String transfortmation;
62 @SerializedName("ChannelGroup")
64 private @Nullable String channelGroup;
65 @SerializedName("actions")
67 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
68 @SerializedName("readmeComment")
70 private @Nullable String readmeComment;
72 public String getProperty() {
73 final String property = this.property;
74 return (property != null) ? property : "";
77 public void setProperty(String property) {
78 this.property = property;
81 public int getSiid() {
82 final Integer siid = this.siid;
84 return siid.intValue();
90 public void setSiid(Integer siid) {
94 public int getPiid() {
95 final Integer piid = this.piid;
97 return piid.intValue();
103 public void setPiid(Integer piid) {
107 public boolean isMiOt() {
108 if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
115 public String getFriendlyName() {
116 final String fn = friendlyName;
117 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
120 public void setFriendlyName(String friendlyName) {
121 this.friendlyName = friendlyName;
124 public String getChannel() {
125 final @Nullable String channel = this.channel;
126 return channel != null ? channel : "";
129 public void setChannel(String channel) {
130 this.channel = channel;
133 public String getChannelType() {
134 final @Nullable String ct = channelType;
135 if (ct == null || ct.isEmpty()) {
136 return BINDING_ID + ":" + getChannel();
138 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
142 public void setChannelType(String channelType) {
143 this.channelType = channelType;
146 public String getType() {
147 final @Nullable String type = this.type;
148 return type != null ? type : "";
151 public void setType(String type) {
155 public Boolean getRefresh() {
156 final @Nullable Boolean rf = refresh;
157 return rf != null && rf.booleanValue() && !getProperty().isEmpty();
160 public void setRefresh(Boolean refresh) {
161 this.refresh = refresh;
164 public String getChannelGroup() {
165 final @Nullable String channelGroup = this.channelGroup;
166 return channelGroup != null ? channelGroup : "";
169 public void setChannelGroup(String channelGroup) {
170 this.channelGroup = channelGroup;
173 public List<MiIoDeviceAction> getActions() {
174 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
175 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
178 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
179 this.miIoDeviceActions = miIoDeviceActions;
182 public @Nullable String getTransfortmation() {
183 return transfortmation;
186 public void setTransfortmation(String transfortmation) {
187 this.transfortmation = transfortmation;
190 public String getReadmeComment() {
191 final String readmeComment = this.readmeComment;
192 return (readmeComment != null) ? readmeComment : "";
195 public void setReadmeComment(String readmeComment) {
196 this.readmeComment = readmeComment;
200 public String toString() {
201 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
202 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
203 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";