]> git.basschouten.com Git - openhab-addons.git/commitdiff
[freeboxos] Fix actions to make them available in DSL rules (#17226)
authorlolodomo <lg.hc@free.fr>
Tue, 13 Aug 2024 09:45:15 +0000 (11:45 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Aug 2024 09:45:15 +0000 (11:45 +0200)
Also rename actions to avoid name conflicts.
Fix #17225

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.freeboxos/README.md
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ActivePlayerActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/CallActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/FreeplugActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/HostActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/PlayerActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/RepeaterActions.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ServerActions.java

index 3e11aab99ca5bc9290462b7fbb730ee5e2b7cd59..f2b86cceb3b8fbd24b02a22f7dd14cb553a9f08a 100644 (file)
@@ -211,15 +211,15 @@ The following channels are supported:
 
 The following actions are available in rules/scripting:
 
-| Thing Type  | Action Name      | Parameters              | Description                                          | 
-|-------------|------------------|-------------------------|------------------------------------------------------|
-| host        | wol              | None                    | Sends a wake on lan packet to the lan connected host |
-| player      | reboot           | None                    | Reboots the player device                            |
-| player      | sendKey          | key: String             | Send a key (remote emulation) to the player          |
-| player      | sendLongKey      | key: String             | Sends the key emulating a longpress on the button    |
-| player      | sendMultipleKeys | keys: String            | Sends multiple keys to the player, comma separated   |
-| player      | sendKeyRepeat    | key: String, count: int | Sends the key multiple times                         |
-| server      | reboot           | None                    | Reboots the Freebox Server                           |
-| freeplug    | reset            | None                    | Resets the Freeplug                                  |
-| call        | reset            | None                    | Clears the call log queue                            |
-| repeater    | reboot           | None                    | Reboots the Repeater                                 |
+| Thing Type            | Action Name      | Parameters              | Description                                          |
+|-----------------------|------------------|-------------------------|------------------------------------------------------|
+| host, wifihost        | wol              | None                    | Sends a wake on lan packet to the lan connected host |
+| active-player         | rebootPlayer     | None                    | Reboots the Freebox Player                           |
+| active-player, player | sendKey          | key: String             | Sends a key (remote emulation) to the player         |
+| active-player, player | sendLongKey      | key: String             | Sends a key emulating a longpress on the button      |
+| active-player, player | sendMultipleKeys | keys: String            | Sends multiple keys to the player, comma separated   |
+| active-player, player | sendKeyRepeat    | key: String, count: int | Sends a key multiple times                           |
+| delta, revolution     | rebootServer     | None                    | Reboots the Freebox Server                           |
+| freeplug              | resetPlug        | None                    | Resets the Freeplug                                  |
+| call                  | resetCalls       | None                    | Deletes all calls logged in the queue                |
+| repeater              | rebootRepeater   | None                    | Reboots the Free Repeater                            |
index f9639ab824aa879a8ffdc302fc1b1e10e13f966b..650eb745643c8976eb180446415f669a9e2854b5 100644 (file)
@@ -35,7 +35,7 @@ public class ActivePlayerActions extends PlayerActions {
     private final Logger logger = LoggerFactory.getLogger(ActivePlayerActions.class);
 
     @RuleAction(label = "reboot freebox player", description = "Reboots the Freebox Player")
-    public void reboot() {
+    public void rebootPlayer() {
         logger.debug("Player reboot called");
         PlayerHandler localHandler = this.handler;
         if (localHandler instanceof ActivePlayerHandler apHandler) {
@@ -45,7 +45,11 @@ public class ActivePlayerActions extends PlayerActions {
         }
     }
 
-    public static void reboot(ThingActions actions) {
-        ((ActivePlayerActions) actions).reboot();
+    public static void rebootPlayer(ThingActions actions) {
+        if (actions instanceof ActivePlayerActions activePlayerActions) {
+            activePlayerActions.rebootPlayer();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not an ActivePlayerActions class.");
+        }
     }
 }
index 6d529d2d57d86c93534a3fd647eff45d1d277be9..fcb9ed67c3482c629af6a2b939e329ea59a245ec 100644 (file)
@@ -48,8 +48,8 @@ public class CallActions implements ThingActions {
         return handler;
     }
 
-    @RuleAction(label = "clear call queue", description = "Delete all call logged in the queue")
-    public void reset() {
+    @RuleAction(label = "clear call queue", description = "Deletes all calls logged in the queue")
+    public void resetCalls() {
         logger.debug("Call log clear called");
         CallHandler localHandler = handler;
         if (localHandler != null) {
@@ -58,4 +58,12 @@ public class CallActions implements ThingActions {
             logger.warn("Call Action service ThingHandler is null");
         }
     }
+
+    public static void resetCalls(ThingActions actions) {
+        if (actions instanceof CallActions callActions) {
+            callActions.resetCalls();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a CallActions class.");
+        }
+    }
 }
index 495add037852f68c4c63451098947c5777656915..3d39bb9d64bcd15d9b4146d2afae9a845ed23cfa 100644 (file)
@@ -49,7 +49,7 @@ public class FreeplugActions implements ThingActions {
     }
 
     @RuleAction(label = "reset freeplug", description = "Resets the Freeplug")
-    public void reset() {
+    public void resetPlug() {
         logger.debug("Freeplug reset requested");
         FreeplugHandler plugHandler = this.handler;
         if (plugHandler != null) {
@@ -58,4 +58,12 @@ public class FreeplugActions implements ThingActions {
             logger.warn("Freeplug Action service ThingHandler is null");
         }
     }
+
+    public static void resetPlug(ThingActions actions) {
+        if (actions instanceof FreeplugActions freeplugActions) {
+            freeplugActions.resetPlug();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a FreeplugActions class.");
+        }
+    }
 }
index 04b2b2c2a55ac08e5e6f95e5eb235322e916580d..de62617f4b47266f58a7395c20462497ccf99643 100644 (file)
@@ -48,7 +48,7 @@ public class HostActions implements ThingActions {
         return this.handler;
     }
 
-    @RuleAction(label = "wol host", description = "Awakes a lan host")
+    @RuleAction(label = "wol host", description = "Sends a wake on lan packet to the lan connected host")
     public void wol() {
         logger.debug("Host WOL called");
         HostHandler hostHandler = this.handler;
@@ -58,4 +58,12 @@ public class HostActions implements ThingActions {
             logger.warn("LanHost Action service ThingHandler is null");
         }
     }
+
+    public static void wol(ThingActions actions) {
+        if (actions instanceof HostActions hostActions) {
+            hostActions.wol();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a HostHandler class.");
+        }
+    }
 }
index 26ef622e7f7f511a4af24a34a01f5ef8aa317294..d86be1c77f708ae625ab3a3fe8d0237cba3a5374 100644 (file)
@@ -92,4 +92,36 @@ public class PlayerActions implements ThingActions {
             logger.warn("Freebox Player Action service ThingHandler is null");
         }
     }
+
+    public static void sendKey(ThingActions actions, String key) {
+        if (actions instanceof PlayerActions playerActions) {
+            playerActions.sendKey(key);
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a PlayerActions class.");
+        }
+    }
+
+    public static void sendLongKey(ThingActions actions, String key) {
+        if (actions instanceof PlayerActions playerActions) {
+            playerActions.sendLongKey(key);
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a PlayerActions class.");
+        }
+    }
+
+    public static void sendMultipleKeys(ThingActions actions, String keys) {
+        if (actions instanceof PlayerActions playerActions) {
+            playerActions.sendMultipleKeys(keys);
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a PlayerActions class.");
+        }
+    }
+
+    public static void sendKeyRepeat(ThingActions actions, String key, int count) {
+        if (actions instanceof PlayerActions playerActions) {
+            playerActions.sendKeyRepeat(key, count);
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a PlayerActions class.");
+        }
+    }
 }
index bbfd7e802acd5d87b67421a2a5549f6bd1f4eba2..f29dc884a89bc061de4a22d7509a36f6f3d39ad9 100644 (file)
@@ -49,7 +49,7 @@ public class RepeaterActions implements ThingActions {
     }
 
     @RuleAction(label = "reboot free repeater", description = "Reboots the Free Repeater")
-    public void reboot() {
+    public void rebootRepeater() {
         logger.debug("Repeater reboot called");
         RepeaterHandler localHandler = this.handler;
         if (localHandler != null) {
@@ -58,4 +58,12 @@ public class RepeaterActions implements ThingActions {
             logger.warn("Repeater Action service ThingHandler is null");
         }
     }
+
+    public static void rebootRepeater(ThingActions actions) {
+        if (actions instanceof RepeaterActions repeaterActions) {
+            repeaterActions.rebootRepeater();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a RepeaterActions class.");
+        }
+    }
 }
index d111c807a030033a9cfd12daa8855d50e5155297..be10ad8932ad35fcd4de8802fc173a011b6e2836 100644 (file)
@@ -49,13 +49,21 @@ public class ServerActions implements ThingActions {
     }
 
     @RuleAction(label = "reboot freebox server", description = "Reboots the Freebox Server")
-    public void reboot() {
+    public void rebootServer() {
         logger.debug("Server reboot called");
         ServerHandler serverHandler = this.handler;
         if (serverHandler != null) {
             serverHandler.reboot();
         } else {
-            logger.warn("Freebox Action service ThingHandler is null");
+            logger.warn("Freebox Server Action service ThingHandler is null");
+        }
+    }
+
+    public static void rebootServer(ThingActions actions) {
+        if (actions instanceof ServerActions serverActions) {
+            serverActions.rebootServer();
+        } else {
+            throw new IllegalArgumentException("actions parameter is not a ServerActions class.");
         }
     }
 }