2 * Copyright (c) 2010-2022 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.JsonElement;
26 import com.google.gson.annotations.Expose;
27 import com.google.gson.annotations.SerializedName;
30 * Mapping properties from json
32 * @author Marcel Verpaalen - Initial contribution
35 public class MiIoBasicChannel {
37 @SerializedName("property")
39 private @Nullable String property;
40 @SerializedName("siid")
42 private @Nullable Integer siid;
43 @SerializedName("piid")
45 private @Nullable Integer piid;
46 @SerializedName("friendlyName")
48 private @Nullable String friendlyName;
49 @SerializedName("channel")
51 private @Nullable String channel;
52 @SerializedName("description")
54 private @Nullable String description;
55 @SerializedName("channelType")
57 private @Nullable String channelType;
58 @SerializedName("type")
60 private @Nullable String type;
61 @SerializedName("unit")
63 private @Nullable String unit;
64 @SerializedName("stateDescription")
66 private @Nullable StateDescriptionDTO stateDescription;
67 @SerializedName("refresh")
69 private @Nullable Boolean refresh;
70 @SerializedName("refreshInterval")
72 private @Nullable Integer refreshInterval;
73 @SerializedName("customRefreshCommand")
75 private @Nullable String channelCustomRefreshCommand;
76 @SerializedName("customRefreshParameters")
78 private @Nullable JsonElement customRefreshParameters;
79 @SerializedName("transformation")
81 private @Nullable String transformation;
82 @SerializedName("transformations")
84 private @Nullable List<String> transformations;
85 @SerializedName("ChannelGroup")
87 private @Nullable String channelGroup;
88 @SerializedName("actions")
90 private @Nullable List<MiIoDeviceAction> miIoDeviceActions = new ArrayList<>();
91 @SerializedName("category")
93 private @Nullable String category;
94 @SerializedName("tags")
96 private @Nullable LinkedHashSet<String> tags;
97 @SerializedName("readmeComment")
99 private @Nullable String readmeComment;
101 public String getProperty() {
102 final String property = this.property;
103 return (property != null) ? property : "";
106 public void setProperty(@Nullable String property) {
107 this.property = property;
110 public int getSiid() {
111 final Integer siid = this.siid;
113 return siid.intValue();
119 public void setSiid(@Nullable Integer siid) {
123 public int getPiid() {
124 final Integer piid = this.piid;
126 return piid.intValue();
132 public void setPiid(@Nullable Integer piid) {
136 public boolean isMiOt() {
137 return (piid != null && siid != null && (getPiid() != 0 || getSiid() != 0));
140 public String getFriendlyName() {
141 final String fn = friendlyName;
142 return (fn == null || type == null || fn.isEmpty()) ? getChannel() : fn;
145 public void setFriendlyName(@Nullable String friendlyName) {
146 this.friendlyName = friendlyName;
149 public String getChannel() {
150 final @Nullable String channel = this.channel;
151 return channel != null ? channel : "";
154 public void setChannel(@Nullable String channel) {
155 this.channel = channel;
158 public String getDescription() {
159 final String description = this.description;
160 return description != null ? description : "";
163 public void setDescription(@Nullable String description) {
164 this.description = description;
167 public String getChannelType() {
168 final @Nullable String ct = channelType;
169 if (ct == null || ct.isEmpty()) {
172 return (ct.startsWith("system") ? ct : BINDING_ID + ":" + ct);
176 public void setChannelType(@Nullable String channelType) {
177 this.channelType = channelType;
180 public String getType() {
181 final @Nullable String type = this.type;
182 return type != null ? type : "";
185 public void setType(@Nullable String type) {
189 public String getUnit() {
190 final @Nullable String unit = this.unit;
191 return unit != null ? unit : "";
194 public void setUnit(@Nullable String unit) {
198 public @Nullable StateDescriptionDTO getStateDescription() {
199 return stateDescription;
202 public void setStateDescription(@Nullable StateDescriptionDTO stateDescription) {
203 this.stateDescription = stateDescription;
206 public Boolean getRefresh() {
207 final @Nullable Boolean rf = refresh;
208 return rf != null && rf.booleanValue();
211 public void setRefresh(@Nullable Boolean refresh) {
212 this.refresh = refresh;
215 public Integer getRefreshInterval() {
216 Integer refreshInterval = this.refreshInterval;
217 if (refreshInterval != null) {
218 return refreshInterval;
223 public void setRefresh(@Nullable final Integer interval) {
224 final Integer refreshInterval = interval;
225 if (refreshInterval != null && refreshInterval.intValue() != 1) {
226 this.refreshInterval = refreshInterval;
228 this.refreshInterval = null;
232 public String getChannelCustomRefreshCommand() {
233 final @Nullable String channelCustomRefreshCommand = this.channelCustomRefreshCommand;
234 return channelCustomRefreshCommand != null ? channelCustomRefreshCommand : "";
237 public void setChannelCustomRefreshCommand(@Nullable String channelCustomRefreshCommand) {
238 this.channelCustomRefreshCommand = channelCustomRefreshCommand;
241 public @Nullable final JsonElement getCustomRefreshParameters() {
242 return customRefreshParameters;
245 public final void setCustomRefreshParameters(@Nullable JsonElement customRefreshParameters) {
246 this.customRefreshParameters = customRefreshParameters;
249 public String getChannelGroup() {
250 final @Nullable String channelGroup = this.channelGroup;
251 return channelGroup != null ? channelGroup : "";
254 public void setChannelGroup(@Nullable String channelGroup) {
255 this.channelGroup = channelGroup;
258 public List<MiIoDeviceAction> getActions() {
259 final @Nullable List<MiIoDeviceAction> miIoDeviceActions = this.miIoDeviceActions;
260 return (miIoDeviceActions != null) ? miIoDeviceActions : Collections.emptyList();
263 public void setActions(List<MiIoDeviceAction> miIoDeviceActions) {
264 this.miIoDeviceActions = miIoDeviceActions;
267 public @Nullable String getTransformation() {
268 return transformation;
271 public void setTransformation(@Nullable String transformation) {
272 this.transformation = transformation;
275 public final List<String> getTransformations() {
276 List<String> transformations = this.transformations;
277 if (transformations == null) {
278 transformations = new ArrayList<>();
280 String transformation = this.transformation;
281 if (transformation != null) {
282 List<String> allTransformation = new ArrayList<>(List.of(transformation));
283 allTransformation.addAll(transformations);
284 return allTransformation;
286 return transformations;
289 public final void setTransformations(@Nullable List<String> transformations) {
290 if (transformations != null && !transformations.isEmpty()) {
291 this.transformations = transformations;
293 this.transformations = null;
297 public @Nullable String getCategory() {
301 public void setCategory(@Nullable String category) {
302 this.category = category;
305 public @Nullable LinkedHashSet<String> getTags() {
309 public void setTags(@Nullable LinkedHashSet<String> tags) {
313 public String getReadmeComment() {
314 final String readmeComment = this.readmeComment;
315 return (readmeComment != null) ? readmeComment : "";
318 public void setReadmeComment(@Nullable String readmeComment) {
319 this.readmeComment = readmeComment;
323 public String toString() {
324 return "[ Channel = " + getChannel() + ", friendlyName = " + getFriendlyName() + ", type = " + getType()
325 + ", channelType = " + getChannelType() + ", ChannelGroup = " + getChannelGroup() + ", channel = "
326 + getChannel() + ", property = " + getProperty() + ", refresh = " + getRefresh() + "]";