]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tapocontrol] LightEffects for L530 can now be set (#14972)
authorChristian Wild <40909464+wildcs@users.noreply.github.com>
Wed, 17 May 2023 19:42:46 +0000 (21:42 +0200)
committerGitHub <noreply@github.com>
Wed, 17 May 2023 19:42:46 +0000 (21:42 +0200)
removed 'queryChild' for devices with no childs

Signed-off-by: Christian Wild <christian@wildclan.de>
bundles/org.openhab.binding.tapocontrol/README.md
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoDeviceConnector.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/constants/TapoBindingSettings.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/constants/TapoThingConstants.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoDevice.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoSmartBulb.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java
bundles/org.openhab.binding.tapocontrol/src/main/resources/OH-INF/i18n/tapocontrol.properties
bundles/org.openhab.binding.tapocontrol/src/main/resources/OH-INF/thing/L530.xml

index f0b18ba26c1c56a206bdfd809b720471b4fbc9c9..b429f3c4691c605d0c14e28ef826784eca720f19 100644 (file)
@@ -70,9 +70,9 @@ All devices support some of the following channels:
 |           | output2          | Switch                 | Power socket 2 on or off            | P300                                                             |
 |           | output3          | Switch                 | Power socket 3 on or off            | P300                                                             |
 |           | brightness       | Dimmer                 | Brightness 0-100%                   | 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                                                 |
-| effects   | fxName           | String                 | Active lightning effect (readonly)  | L530                                                             |
+|           | colorTemperature | Number                 | White-Color-Temp 2500-6500K         | L510, L530, L610, L630, L900, L920                               |
+|           | color            | Color                  | Color                               | L530, L630, L900, L920                                           |
+| effects   | fxName           | String                 | Active lightning effect             | L530                                                             |
 | 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             |
 | energy    | actualPower      | Number:Power           | actual Power (Watt)                 | P110, P115                                                       |
index 0913654bc7dd559fc274ed1c835f4dfdaa8c3d55..7bd5af66773dbc708796cbeba509b01380d310f4 100644 (file)
@@ -142,17 +142,28 @@ public class TapoDeviceConnector extends TapoDeviceHttpApi {
      * @param value Value to send to control
      */
     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();
         if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) {
             this.lastSent = now;
 
             /* create payload */
             PayloadBuilder plBuilder = new PayloadBuilder();
-            plBuilder.method = DEVICE_CMD_SETINFO;
+            plBuilder.method = method;
             plBuilder.addParameter(name, value);
             String payload = plBuilder.getPayload();
 
-            sendSecurePasstrhroug(payload, DEVICE_CMD_SETINFO);
+            sendSecurePasstrhroug(payload, method);
         } else {
             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)
      */
     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();
         if (now > this.lastSent + TAPO_SEND_MIN_GAP_MS) {
             this.lastSent = now;
 
             /* create payload */
             PayloadBuilder plBuilder = new PayloadBuilder();
-            plBuilder.method = DEVICE_CMD_SETINFO;
+            plBuilder.method = method;
             for (HashMap.Entry<String, Object> entry : map.entrySet()) {
                 plBuilder.addParameter(entry.getKey(), entry.getValue());
             }
             String payload = plBuilder.getPayload();
 
-            sendSecurePasstrhroug(payload, DEVICE_CMD_SETINFO);
+            sendSecurePasstrhroug(payload, method);
         } else {
             logger.debug("({}) command not sent becauso of min_gap: {}", uid, now + " <- " + lastSent);
         }
@@ -208,7 +229,6 @@ public class TapoDeviceConnector extends TapoDeviceHttpApi {
      */
     public void queryInfo() {
         queryInfo(false);
-        queryChildDevices();
     }
 
     /**
index 59c95b5d41c2deca4fbfc9dffeba56cce8ed617d..e9024b64d7d61c3db7997d3c4e97ac1db8d40c40 100644 (file)
@@ -56,4 +56,5 @@ public class TapoBindingSettings {
     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_CUSTOM = "custom_command";
+    public static final String DEVICE_CMD_SET_LIGHT_FX = "set_dynamic_light_effect_rule_enable";
 }
index d64570ea8f9ac2b348e4446d984f52686a5fa6cf..d006c2de9d3fa94b3145548239cf04888aeb21f7 100644 (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_COLORTEMPRANGE = "color_temp_range";
     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_ENABLE = "enable";
     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_DYNAMIC_ENABLE = "dynamic_light_effect_enable";
     public static final String JSON_KEY_LIGHTNING_DYNAMIC_ID = "dynamic_light_effect_id";
+
     // energy monitoring
     public static final String JSON_KEY_ENERGY_POWER = "current_power";
     public static final String JSON_KEY_ENERGY_RUNTIME_TODAY = "today_runtime";
index dc2455f3380950740c134b5846a5a4483985fbaf..d62bd192c0f0567442af979dc3f22fe233230b41 100644 (file)
@@ -439,7 +439,7 @@ public abstract class TapoDevice extends BaseThingHandler {
         try {
             loginSuccess = connector.login();
             if (loginSuccess) {
-                connector.queryInfo();
+                queryDeviceInfo(true);
             } else {
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, deviceError.getMessage());
             }
index 578dbaf00aa12b8ec2b588cb422a9fe569eb4612..d55c2c27d9e8e51e3e5402306ccd9652888fd042 100644 (file)
@@ -12,6 +12,7 @@
  */
 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.helpers.TapoUtils.*;
 
@@ -158,15 +159,13 @@ public class TapoSmartBulb extends TapoDevice {
      */
     protected void setLightEffect(String fxName) {
         HashMap<String, Object> newState = new HashMap<>();
-        if (fxName.length() > 0) {
-            newState.put(JSON_KEY_ON, true);
-            newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE, true);
-            newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ID, fxName);
+        if (fxName.length() > 0 && !fxName.equals(JSON_KEY_LIGHTNING_EFFECT_OFF)) {
+            newState.put(JSON_KEY_LIGHTNING_EFFECT_ENABLE, true);
+            newState.put(JSON_KEY_LIGHTNING_EFFECT_ID, fxName);
         } else {
-            newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE, false);
-            newState.put(JSON_KEY_LIGHTNING_DYNAMIC_ID, "");
+            newState.put(JSON_KEY_LIGHTNING_EFFECT_ENABLE, false);
         }
-        connector.sendDeviceCommands(newState);
+        connector.sendDeviceCommands(DEVICE_CMD_SET_LIGHT_FX, newState);
     }
 
     /**
index d618fefdc7986cb4024a4bd1f820ad8917d4dd91..65d0cfcb8f4271ed67b15478b2b536a2be7481f6 100644 (file)
@@ -63,14 +63,14 @@ public class TapoLightEffect {
         if (jso.has(JSON_KEY_LIGHTNING_EFFECT)) {
             this.jsonObject = jso.getAsJsonObject(JSON_KEY_LIGHTNING_EFFECT);
             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.custom = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_CUSTOM);
             this.brightness = jsonObjectToInt(jsonObject, JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS);
         } else if (jso.has(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE)) {
             this.jsonObject = jso;
             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 {
             setDefaults();
         }
@@ -83,7 +83,7 @@ public class TapoLightEffect {
     private void setDefaults() {
         this.jsonObject = new JsonObject();
         this.enable = false;
-        this.id = "";
+        this.id = JSON_KEY_LIGHTNING_EFFECT_OFF;
         this.name = "";
         this.custom = false;
         this.brightness = 100;
index c53e9bb902f779fb54cf70ee2744296e4ebf9923..ed585295995b7e60e5d0d1142ae36f466bc80aa2 100644 (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.l530fxList.label = Light Effect Theme
 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.L1 = Party
 channel-type.tapocontrol.l530fxList.state.option.L2 = Relax
index 85b08cd5f915b7c1136407edb0e6d00b6306f69d..185d98cc95d3c6a7560783b7abbc00613d4fa87e 100644 (file)
@@ -36,9 +36,9 @@
                <item-type>String</item-type>
                <label>Light Effect Theme</label>
                <description>Name of active lightning effect</description>
-               <state readOnly="true">
+               <state readOnly="false">
                        <options>
-                               <option value="">None (No FX)</option>
+                               <option value="off">None (No FX)</option>
                                <option value="custom">Custom</option>
                                <option value="L1">Party</option>
                                <option value="L2">Relax</option>