[tapocontrol] LightEffects for L530 can now be set (#14972)

removed 'queryChild' for devices with no childs

Signed-off-by: Christian Wild <christian@wildclan.de>
This commit is contained in:
Christian Wild 2023-05-17 21:42:46 +02:00 committed by GitHub
parent ccab566172
commit 6ab8111f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 22 deletions

View File

@ -70,9 +70,9 @@ All devices support some of the following channels:
| | output2 | Switch | Power socket 2 on or off | P300 | | | output2 | Switch | Power socket 2 on or off | P300 |
| | output3 | Switch | Power socket 3 on or off | P300 | | | output3 | Switch | Power socket 3 on or off | P300 |
| | brightness | Dimmer | Brightness 0-100% | L510, L530, L610, L630, L900, L920 | | | brightness | Dimmer | Brightness 0-100% | L510, L530, L610, L630, L900, L920 |
| | colorTemperature | Number | White-Color-Temp 2500-6500K | L510, L530, L610, L630, L900, L920 | | | colorTemperature | Number | White-Color-Temp 2500-6500K | L510, L530, L610, L630, L900, L920 |
| | color | Color | Color | L530, L630, L900, L920 | | | color | Color | Color | L530, L630, L900, L920 |
| effects | fxName | String | Active lightning effect (readonly) | L530 | | effects | fxName | String | Active lightning effect | L530 |
| device | wifiSignal | Number | WiFi-quality-level | P100, P105, P110, P115, L510, L530, L610, L630, L900, L920, L930 | | device | wifiSignal | Number | WiFi-quality-level | P100, P105, P110, P115, L510, L530, L610, L630, L900, L920, L930 |
| | onTime | Number:Time | seconds output is on | P100, P105, P110, P115, L510, L530, L900, L920, L930 | | | onTime | Number:Time | seconds output is on | P100, P105, P110, P115, L510, L530, L900, L920, L930 |
| energy | actualPower | Number:Power | actual Power (Watt) | P110, P115 | | energy | actualPower | Number:Power | actual Power (Watt) | P110, P115 |

View File

@ -142,17 +142,28 @@ public class TapoDeviceConnector extends TapoDeviceHttpApi {
* @param value Value to send to control * @param value Value to send to control
*/ */
public void sendDeviceCommand(String name, Object value) { public void sendDeviceCommand(String name, Object value) {
sendDeviceCommand(DEVICE_CMD_SETINFO, name, value);
}
/**
* send "set_device_info" command to device
*
* @param method Method command belongs to
* @param name Name of command to send
* @param value Value to send to control
*/
public void sendDeviceCommand(String method, String name, Object value) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) { if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) {
this.lastSent = now; this.lastSent = now;
/* create payload */ /* create payload */
PayloadBuilder plBuilder = new PayloadBuilder(); PayloadBuilder plBuilder = new PayloadBuilder();
plBuilder.method = DEVICE_CMD_SETINFO; plBuilder.method = method;
plBuilder.addParameter(name, value); plBuilder.addParameter(name, value);
String payload = plBuilder.getPayload(); String payload = plBuilder.getPayload();
sendSecurePasstrhroug(payload, DEVICE_CMD_SETINFO); sendSecurePasstrhroug(payload, method);
} else { } else {
logger.debug("({}) command not sent becauso of min_gap: {}", uid, now + " <- " + lastSent); logger.debug("({}) command not sent becauso of min_gap: {}", uid, now + " <- " + lastSent);
} }
@ -185,19 +196,29 @@ public class TapoDeviceConnector extends TapoDeviceHttpApi {
* @param map HashMap<String, Object> (name, value of parameter) * @param map HashMap<String, Object> (name, value of parameter)
*/ */
public void sendDeviceCommands(HashMap<String, Object> map) { public void sendDeviceCommands(HashMap<String, Object> map) {
sendDeviceCommands(DEVICE_CMD_SETINFO, map);
}
/**
* send multiple commands to device
*
* @param method Method command belongs to
* @param map HashMap<String, Object> (name, value of parameter)
*/
public void sendDeviceCommands(String method, HashMap<String, Object> map) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) { if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) {
this.lastSent = now; this.lastSent = now;
/* create payload */ /* create payload */
PayloadBuilder plBuilder = new PayloadBuilder(); PayloadBuilder plBuilder = new PayloadBuilder();
plBuilder.method = DEVICE_CMD_SETINFO; plBuilder.method = method;
for (HashMap.Entry<String, Object> entry : map.entrySet()) { for (HashMap.Entry<String, Object> entry : map.entrySet()) {
plBuilder.addParameter(entry.getKey(), entry.getValue()); plBuilder.addParameter(entry.getKey(), entry.getValue());
} }
String payload = plBuilder.getPayload(); String payload = plBuilder.getPayload();
sendSecurePasstrhroug(payload, DEVICE_CMD_SETINFO); sendSecurePasstrhroug(payload, method);
} else { } else {
logger.debug("({}) command not sent becauso of min_gap: {}", uid, now + " <- " + lastSent); logger.debug("({}) command not sent becauso of min_gap: {}", uid, now + " <- " + lastSent);
} }
@ -208,7 +229,6 @@ public class TapoDeviceConnector extends TapoDeviceHttpApi {
*/ */
public void queryInfo() { public void queryInfo() {
queryInfo(false); queryInfo(false);
queryChildDevices();
} }
/** /**

View File

@ -56,4 +56,5 @@ public class TapoBindingSettings {
public static final String DEVICE_CMD_CONTROL_CHILD = "control_child"; public static final String DEVICE_CMD_CONTROL_CHILD = "control_child";
public static final String DEVICE_CMD_MULTIPLE_REQ = "multipleRequest"; public static final String DEVICE_CMD_MULTIPLE_REQ = "multipleRequest";
public static final String DEVICE_CMD_CUSTOM = "custom_command"; public static final String DEVICE_CMD_CUSTOM = "custom_command";
public static final String DEVICE_CMD_SET_LIGHT_FX = "set_dynamic_light_effect_rule_enable";
} }

View File

@ -138,12 +138,14 @@ public class TapoThingConstants {
public static final String JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS = "brightness"; public static final String JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS = "brightness";
public static final String JSON_KEY_LIGHTNING_EFFECT_COLORTEMPRANGE = "color_temp_range"; public static final String JSON_KEY_LIGHTNING_EFFECT_COLORTEMPRANGE = "color_temp_range";
public static final String JSON_KEY_LIGHTNING_EFFECT_CUSTOM = "custom"; public static final String JSON_KEY_LIGHTNING_EFFECT_CUSTOM = "custom";
public static final String JSON_KEY_LIGHTNING_EFFECT_OFF = "off";
public static final String JSON_KEY_LIGHTNING_EFFECT_DISPLAYCOLORS = "displayColors"; public static final String JSON_KEY_LIGHTNING_EFFECT_DISPLAYCOLORS = "displayColors";
public static final String JSON_KEY_LIGHTNING_EFFECT_ENABLE = "enable"; public static final String JSON_KEY_LIGHTNING_EFFECT_ENABLE = "enable";
public static final String JSON_KEY_LIGHTNING_EFFECT_ID = "id"; public static final String JSON_KEY_LIGHTNING_EFFECT_ID = "id";
public static final String JSON_KEY_LIGHTNING_EFFECT_NAME = "name"; public static final String JSON_KEY_LIGHTNING_EFFECT_NAME = "name";
public static final String JSON_KEY_LIGHTNING_DYNAMIC_ENABLE = "dynamic_light_effect_enable"; public static final String JSON_KEY_LIGHTNING_DYNAMIC_ENABLE = "dynamic_light_effect_enable";
public static final String JSON_KEY_LIGHTNING_DYNAMIC_ID = "dynamic_light_effect_id"; public static final String JSON_KEY_LIGHTNING_DYNAMIC_ID = "dynamic_light_effect_id";
// energy monitoring // energy monitoring
public static final String JSON_KEY_ENERGY_POWER = "current_power"; public static final String JSON_KEY_ENERGY_POWER = "current_power";
public static final String JSON_KEY_ENERGY_RUNTIME_TODAY = "today_runtime"; public static final String JSON_KEY_ENERGY_RUNTIME_TODAY = "today_runtime";

View File

@ -439,7 +439,7 @@ public abstract class TapoDevice extends BaseThingHandler {
try { try {
loginSuccess = connector.login(); loginSuccess = connector.login();
if (loginSuccess) { if (loginSuccess) {
connector.queryInfo(); queryDeviceInfo(true);
} else { } else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, deviceError.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, deviceError.getMessage());
} }

View File

@ -12,6 +12,7 @@
*/ */
package org.openhab.binding.tapocontrol.internal.device; package org.openhab.binding.tapocontrol.internal.device;
import static org.openhab.binding.tapocontrol.internal.constants.TapoBindingSettings.*;
import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*; import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*; import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
@ -158,15 +159,13 @@ public class TapoSmartBulb extends TapoDevice {
*/ */
protected void setLightEffect(String fxName) { protected void setLightEffect(String fxName) {
HashMap<String, Object> newState = new HashMap<>(); HashMap<String, Object> newState = new HashMap<>();
if (fxName.length() > 0) { if (fxName.length() > 0 && !fxName.equals(JSON_KEY_LIGHTNING_EFFECT_OFF)) {
newState.put(JSON_KEY_ON, true); newState.put(JSON_KEY_LIGHTNING_EFFECT_ENABLE, true);
newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE, true); newState.put(JSON_KEY_LIGHTNING_EFFECT_ID, fxName);
newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ID, fxName);
} else { } else {
newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE, false); newState.put(JSON_KEY_LIGHTNING_EFFECT_ENABLE, false);
newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ID, "");
} }
connector.sendDeviceCommands(newState); connector.sendDeviceCommands(DEVICE_CMD_SET_LIGHT_FX, newState);
} }
/** /**

View File

@ -63,14 +63,14 @@ public class TapoLightEffect {
if (jso.has(JSON_KEY_LIGHTNING_EFFECT)) { if (jso.has(JSON_KEY_LIGHTNING_EFFECT)) {
this.jsonObject = jso.getAsJsonObject(JSON_KEY_LIGHTNING_EFFECT); this.jsonObject = jso.getAsJsonObject(JSON_KEY_LIGHTNING_EFFECT);
this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ENABLE); this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ENABLE);
this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ID); this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ID, JSON_KEY_LIGHTNING_EFFECT_OFF);
this.name = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_NAME); this.name = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_NAME);
this.custom = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_CUSTOM); this.custom = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_CUSTOM);
this.brightness = jsonObjectToInt(jsonObject, JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS); this.brightness = jsonObjectToInt(jsonObject, JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS);
} else if (jso.has(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE)) { } else if (jso.has(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE)) {
this.jsonObject = jso; this.jsonObject = jso;
this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ENABLE); this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ENABLE);
this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ID); this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ID, JSON_KEY_LIGHTNING_EFFECT_OFF);
} else { } else {
setDefaults(); setDefaults();
} }
@ -83,7 +83,7 @@ public class TapoLightEffect {
private void setDefaults() { private void setDefaults() {
this.jsonObject = new JsonObject(); this.jsonObject = new JsonObject();
this.enable = false; this.enable = false;
this.id = ""; this.id = JSON_KEY_LIGHTNING_EFFECT_OFF;
this.name = ""; this.name = "";
this.custom = false; this.custom = false;
this.brightness = 100; this.brightness = 100;

View File

@ -91,7 +91,7 @@ channel-type.tapocontrol.fade.label = Fade Light
channel-type.tapocontrol.fade.description = Make the light darker or lighter slowly channel-type.tapocontrol.fade.description = Make the light darker or lighter slowly
channel-type.tapocontrol.l530fxList.label = Light Effect Theme channel-type.tapocontrol.l530fxList.label = Light Effect Theme
channel-type.tapocontrol.l530fxList.description = Name of active lightning effect channel-type.tapocontrol.l530fxList.description = Name of active lightning effect
channel-type.tapocontrol.l530fxList.state.option. = None (No FX) channel-type.tapocontrol.l530fxList.state.option.off = None (No FX)
channel-type.tapocontrol.l530fxList.state.option.custom = Custom channel-type.tapocontrol.l530fxList.state.option.custom = Custom
channel-type.tapocontrol.l530fxList.state.option.L1 = Party channel-type.tapocontrol.l530fxList.state.option.L1 = Party
channel-type.tapocontrol.l530fxList.state.option.L2 = Relax channel-type.tapocontrol.l530fxList.state.option.L2 = Relax

View File

@ -36,9 +36,9 @@
<item-type>String</item-type> <item-type>String</item-type>
<label>Light Effect Theme</label> <label>Light Effect Theme</label>
<description>Name of active lightning effect</description> <description>Name of active lightning effect</description>
<state readOnly="true"> <state readOnly="false">
<options> <options>
<option value="">None (No FX)</option> <option value="off">None (No FX)</option>
<option value="custom">Custom</option> <option value="custom">Custom</option>
<option value="L1">Party</option> <option value="L1">Party</option>
<option value="L2">Relax</option> <option value="L2">Relax</option>