From 338be49c77e96d4d2cfa710c7904c94fb5563fbb Mon Sep 17 00:00:00 2001 From: lolodomo Date: Tue, 13 Aug 2024 11:45:15 +0200 Subject: [PATCH] [freeboxos] Fix actions to make them available in DSL rules (#17226) Also rename actions to avoid name conflicts. Fix #17225 Signed-off-by: Laurent Garnier Signed-off-by: Ciprian Pascu --- .../org.openhab.binding.freeboxos/README.md | 24 +++++++------- .../internal/action/ActivePlayerActions.java | 10 ++++-- .../internal/action/CallActions.java | 12 +++++-- .../internal/action/FreeplugActions.java | 10 +++++- .../internal/action/HostActions.java | 10 +++++- .../internal/action/PlayerActions.java | 32 +++++++++++++++++++ .../internal/action/RepeaterActions.java | 10 +++++- .../internal/action/ServerActions.java | 12 +++++-- 8 files changed, 98 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.freeboxos/README.md b/bundles/org.openhab.binding.freeboxos/README.md index 3e11aab99ca..f2b86cceb3b 100644 --- a/bundles/org.openhab.binding.freeboxos/README.md +++ b/bundles/org.openhab.binding.freeboxos/README.md @@ -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 | diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ActivePlayerActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ActivePlayerActions.java index f9639ab824a..650eb745643 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ActivePlayerActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ActivePlayerActions.java @@ -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."); + } } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/CallActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/CallActions.java index 6d529d2d57d..fcb9ed67c34 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/CallActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/CallActions.java @@ -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."); + } + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/FreeplugActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/FreeplugActions.java index 495add03785..3d39bb9d64b 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/FreeplugActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/FreeplugActions.java @@ -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."); + } + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/HostActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/HostActions.java index 04b2b2c2a55..de62617f4b4 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/HostActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/HostActions.java @@ -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."); + } + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/PlayerActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/PlayerActions.java index 26ef622e7f7..d86be1c77f7 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/PlayerActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/PlayerActions.java @@ -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."); + } + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/RepeaterActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/RepeaterActions.java index bbfd7e802ac..f29dc884a89 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/RepeaterActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/RepeaterActions.java @@ -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."); + } + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ServerActions.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ServerActions.java index d111c807a03..be10ad8932a 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ServerActions.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/action/ServerActions.java @@ -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."); } } }