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("customRefreshCommand")
61 private @Nullable String channelCustomRefreshCommand;
62 @SerializedName("transformation")
64 private @Nullable String transfortmation;
65 @SerializedName("ChannelGroup")
67 private @Nullable String channelGroup;
68 @SerializedName("actions")
70 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
71 @SerializedName("readmeComment")
73 private @Nullable String readmeComment;
75 public String getProperty() {
76 final String property = this.property;
77 return (property != null) ? property : "";
80 public void setProperty(String property) {
81 this.property = property;
84 public int getSiid() {
85 final Integer siid = this.siid;
87 return siid.intValue();
93 public void setSiid(Integer siid) {
97 public int getPiid() {
98 final Integer piid = this.piid;
100 return piid.intValue();
106 public void setPiid(Integer piid) {
110 public boolean isMiOt() {
111 if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
118 public String getFriendlyName() {
119 final String fn = friendlyName;
120 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
123 public void setFriendlyName(String friendlyName) {
124 this.friendlyName = friendlyName;
127 public String getChannel() {
128 final @Nullable String channel = this.channel;
129 return channel != null ? channel : "";
132 public void setChannel(String channel) {
133 this.channel = channel;
136 public String getChannelType() {
137 final @Nullable String ct = channelType;
138 if (ct == null || ct.isEmpty()) {
141 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
145 public void setChannelType(String channelType) {
146 this.channelType = channelType;
149 public String getType() {
150 final @Nullable String type = this.type;
151 return type != null ? type : "";
154 public void setType(String type) {
158 public Boolean getRefresh() {
159 final @Nullable Boolean rf = refresh;
160 return rf != null && rf.booleanValue() && !getProperty().isEmpty();
163 public void setRefresh(Boolean refresh) {
164 this.refresh = refresh;
167 public String getChannelCustomRefreshCommand() {
168 final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
169 return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
172 public void setChannelCustomRefreshCommand(String channelCustomRefreshCommand) {
173 this.channelCustomRefreshCommand = channelCustomRefreshCommand;
176 public String getChannelGroup() {
177 final @Nullable String channelGroup = this.channelGroup;
178 return channelGroup != null ? channelGroup : "";
181 public void setChannelGroup(String channelGroup) {
182 this.channelGroup = channelGroup;
185 public List<MiIoDeviceAction> getActions() {
186 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
187 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
190 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
191 this.miIoDeviceActions = miIoDeviceActions;
194 public @Nullable String getTransfortmation() {
195 return transfortmation;
198 public void setTransfortmation(String transfortmation) {
199 this.transfortmation = transfortmation;
202 public String getReadmeComment() {
203 final String readmeComment = this.readmeComment;
204 return (readmeComment != null) ? readmeComment : "";
207 public void setReadmeComment(String readmeComment) {
208 this.readmeComment = readmeComment;
212 public String toString() {
213 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
214 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
215 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";