2 * Copyright (c) 2010-2023 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.yeelight.internal.lib.device;
15 import org.openhab.binding.yeelight.internal.lib.enums.MethodAction;
18 * @author Coaster Li - Initial contribution
20 public class DeviceMethod {
22 public static final String EFFECT_SMOOTH = "smooth";
23 public static final String EFFECT_SUDDEN = "sudden";
25 public static final int CF_END_STATE_RECOVER = 0;
26 public static final int CF_END_STATE_STAY = 1;
27 public static final int CF_END_STATE_TURNOFF = 2;
29 public static final int CF_ITEM_MODE_COLOR = 1;
30 public static final int CF_ITEM_MODE_CT = 2;
31 public static final int CF_ITEM_MODE_SLEEP = 7;
33 public static final String SCENE_TYPE_COLOR = "color";
34 public static final String SCENE_TYPE_HSV = "hsv";
35 public static final String SCENE_TYPE_CT = "ct";
36 public static final String SCENE_TYPE_CF = "cf";
37 public static final String SCENE_TYPE_DELAY = "auto_delay_off";
39 public static final String ADJUST_ACTION_INCREASE = "increase";
40 public static final String ADJUST_ACTION_DECREASE = "decrease";
41 public static final String ADJUST_ACTION_CIRCLE = "circle";
43 public static final String ADJUST_PROP_BRIGHT = "bright";
44 public static final String ADJUST_PROP_CT = "ct";
45 public static final String ADJUST_PROP_COLOR = "color";
47 public static final int MUSIC_ACTION_ON = 1;
48 public static final int MUSIC_ACTION_OFF = 0;
50 private static int sIndex = 0;
52 private String mMethodAction;
53 private Object[] mMethodParams;
54 private String mCustomMethodParams;
57 public DeviceMethod(MethodAction action, Object[] params) {
58 this.mMethodAction = action.action;
59 this.mMethodParams = params;
60 this.mCustomMethodParams = "";
64 public DeviceMethod(String action, String params) {
65 this.mMethodAction = action;
66 this.mMethodParams = null;
67 this.mCustomMethodParams = params;
71 public String getParamsStr() {
72 StringBuilder cmdBuilder = new StringBuilder();
73 cmdBuilder.append("{\"id\":").append(mIndex).append(",");
74 cmdBuilder.append("\"method\":\"").append(mMethodAction).append("\",");
75 cmdBuilder.append("\"params\":[");
76 if (mMethodParams != null && mMethodParams.length > 0) {
77 for (Object param : mMethodParams) {
78 if (param instanceof String) {
79 cmdBuilder.append("\"" + param.toString() + "\"");
81 cmdBuilder.append(Integer.parseInt(param.toString()));
83 cmdBuilder.append(",");
86 cmdBuilder.deleteCharAt(cmdBuilder.length() - 1);
88 cmdBuilder.append("]}\r\n");
89 return cmdBuilder.toString();
92 public String getCustomParamsStr() {
93 StringBuilder cmdBuilder = new StringBuilder();
94 cmdBuilder.append("{\"id\":").append(mIndex).append(",");
95 cmdBuilder.append("\"method\":\"").append(mMethodAction).append("\",");
96 cmdBuilder.append("\"params\":[").append(mCustomMethodParams).append("]}\r\n");
97 return cmdBuilder.toString();
100 public String getCmdId() {
101 return String.valueOf(mIndex);