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("channelType")
53 private @Nullable String channelType;
54 @SerializedName("type")
56 private @Nullable String type;
57 @SerializedName("unit")
59 private @Nullable String unit;
60 @SerializedName("stateDescription")
62 private @Nullable StateDescriptionDTO stateDescription;
63 @SerializedName("refresh")
65 private @Nullable Boolean refresh;
66 @SerializedName("customRefreshCommand")
68 private @Nullable String channelCustomRefreshCommand;
69 @SerializedName("transformation")
71 private @Nullable String transformation;
72 @SerializedName("ChannelGroup")
74 private @Nullable String channelGroup;
75 @SerializedName("actions")
77 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
78 @SerializedName("category")
80 private @Nullable String category;
81 @SerializedName("tags")
83 private @Nullable LinkedHashSet<String> tags;
84 @SerializedName("readmeComment")
86 private @Nullable String readmeComment;
88 public String getProperty() {
89 final String property = this.property;
90 return (property != null) ? property : "";
93 public void setProperty(@Nullable String property) {
94 this.property = property;
97 public int getSiid() {
98 final Integer siid = this.siid;
100 return siid.intValue();
106 public void setSiid(@Nullable Integer siid) {
110 public int getPiid() {
111 final Integer piid = this.piid;
113 return piid.intValue();
119 public void setPiid(@Nullable Integer piid) {
123 public boolean isMiOt() {
124 return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
127 public String getFriendlyName() {
128 final String fn = friendlyName;
129 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
132 public void setFriendlyName(@Nullable String friendlyName) {
133 this.friendlyName = friendlyName;
136 public String getChannel() {
137 final @Nullable String channel = this.channel;
138 return channel != null ? channel : "";
141 public void setChannel(@Nullable String channel) {
142 this.channel = channel;
145 public String getChannelType() {
146 final @Nullable String ct = channelType;
147 if (ct == null || ct.isEmpty()) {
150 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
154 public void setChannelType(@Nullable String channelType) {
155 this.channelType = channelType;
158 public String getType() {
159 final @Nullable String type = this.type;
160 return type != null ? type : "";
163 public void setType(@Nullable String type) {
167 public String getUnit() {
168 final @Nullable String unit = this.unit;
169 return unit != null ? unit : "";
172 public void setUnit(@Nullable String unit) {
176 public @Nullable StateDescriptionDTO getStateDescription() {
177 return stateDescription;
180 public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
181 this.stateDescription = stateDescription;
184 public Boolean getRefresh() {
185 final @Nullable Boolean rf = refresh;
186 return rf != null && rf.booleanValue();
189 public void setRefresh(@Nullable Boolean refresh) {
190 this.refresh = refresh;
193 public String getChannelCustomRefreshCommand() {
194 final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
195 return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
198 public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
199 this.channelCustomRefreshCommand = channelCustomRefreshCommand;
202 public String getChannelGroup() {
203 final @Nullable String channelGroup = this.channelGroup;
204 return channelGroup != null ? channelGroup : "";
207 public void setChannelGroup(@Nullable String channelGroup) {
208 this.channelGroup = channelGroup;
211 public List<MiIoDeviceAction> getActions() {
212 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
213 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
216 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
217 this.miIoDeviceActions = miIoDeviceActions;
220 public @Nullable String getTransformation() {
221 return transformation;
224 public void setTransformation(@Nullable String transformation) {
225 this.transformation = transformation;
228 public @Nullable String getCategory() {
232 public void setCategory(@Nullable String category) {
233 this.category = category;
236 public @Nullable LinkedHashSet<String> getTags() {
240 public void setTags(@Nullable LinkedHashSet<String> tags) {
244 public String getReadmeComment() {
245 final String readmeComment = this.readmeComment;
246 return (readmeComment != null) ? readmeComment : "";
249 public void setReadmeComment(@Nullable String readmeComment) {
250 this.readmeComment = readmeComment;
254 public String toString() {
255 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
256 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
257 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";