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<>();
69 public String getProperty() {
70 final String property = this.property;
71 return (property != null) ? property : "";
74 public void setProperty(String property) {
75 this.property = property;
78 public int getSiid() {
79 final Integer siid = this.siid;
81 return siid.intValue();
87 public void setSiid(Integer siid) {
91 public int getPiid() {
92 final Integer piid = this.piid;
94 return piid.intValue();
100 public void setPiid(Integer piid) {
104 public boolean isMiOt() {
105 if (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0)) {
112 public String getFriendlyName() {
113 final String fn = friendlyName;
114 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
117 public void setFriendlyName(String friendlyName) {
118 this.friendlyName = friendlyName;
121 public String getChannel() {
122 final @Nullable String channel = this.channel;
123 return channel != null ? channel : "";
126 public void setChannel(String channel) {
127 this.channel = channel;
130 public String getChannelType() {
131 final @Nullable String ct = channelType;
132 if (ct == null || ct.isEmpty()) {
133 return BINDING_ID + ":" + getChannel();
135 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
139 public void setChannelType(String channelType) {
140 this.channelType = channelType;
143 public String getType() {
144 final @Nullable String type = this.type;
145 return type != null ? type : "";
148 public void setType(String type) {
152 public Boolean getRefresh() {
153 final @Nullable Boolean rf = refresh;
154 return rf != null && rf.booleanValue() && !getProperty().isEmpty();
157 public void setRefresh(Boolean refresh) {
158 this.refresh = refresh;
161 public String getChannelGroup() {
162 final @Nullable String channelGroup = this.channelGroup;
163 return channelGroup != null ? channelGroup : "";
166 public void setChannelGroup(String channelGroup) {
167 this.channelGroup = channelGroup;
170 public List<MiIoDeviceAction> getActions() {
171 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
172 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
175 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
176 this.miIoDeviceActions = miIoDeviceActions;
179 public @Nullable String getTransfortmation() {
180 return transfortmation;
183 public void setTransfortmation(String transfortmation) {
184 this.transfortmation = transfortmation;
188 public String toString() {
189 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
190 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
191 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";