]> git.basschouten.com Git - openhab-addons.git/commitdiff
[pushover] Added universal action providing all available parameters (#10422)
authorChristoph Weitkamp <github@christophweitkamp.de>
Wed, 31 Mar 2021 20:00:29 +0000 (22:00 +0200)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 20:00:29 +0000 (22:00 +0200)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.pushover/README.md
bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/actions/PushoverActions.java
bundles/org.openhab.binding.pushover/src/main/resources/OH-INF/i18n/pushover.properties
bundles/org.openhab.binding.pushover/src/main/resources/OH-INF/i18n/pushover_de.properties

index f20be7d7c2ded7d2626a7712894a114e533726f7..f19e70bdfe8931cb29113596b3f66519de62106d 100644 (file)
@@ -32,6 +32,10 @@ Currently the binding does not support any Channels.
 
 All actions return a `Boolean` value to indicate if the message was sent successfully or not.
 The parameter `message` is **mandatory**, the `title` parameter defaults to whatever value you defined in the `title` related configuration parameter.
+Parameters declared as `@Nullable` are not optional.
+One has to pass a `null` value if it should be skipped or the default value for it should be used.
+
+- `sendMessage(String message, @Nullable String title, @Nullable String sound, @Nullable String url, @Nullable String urlTitle, @Nullable String attachment, @Nullable String contentType, @Nullable Integer priority, @Nullable String device)` - This method is used to send a plain text message providing all available parameters.
 
 - `sendMessage(String message, @Nullable String title)` - This method is used to send a plain text message.
 
index 2b85055fd79e806405c9cb1a26b5fc417ebd5f67..ebef8cdc058d5c3572d76c4c5669c76f67512538 100644 (file)
@@ -12,7 +12,7 @@
  */
 package org.openhab.binding.pushover.internal.actions;
 
-import static org.openhab.binding.pushover.internal.PushoverBindingConstants.DEFAULT_TITLE;
+import static org.openhab.binding.pushover.internal.PushoverBindingConstants.*;
 import static org.openhab.binding.pushover.internal.connection.PushoverMessageBuilder.*;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -43,6 +43,53 @@ public class PushoverActions implements ThingActions {
 
     private @NonNullByDefault({}) PushoverAccountHandler accountHandler;
 
+    @RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
+    public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessage(
+            @ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
+            @ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
+            @ActionInput(name = "sound", label = "@text/sendMessageActionInputSoundLabel", description = "@text/sendMessageActionInputSoundDescription", type = "java.lang.String", defaultValue = DEFAULT_SOUND) @Nullable String sound,
+            @ActionInput(name = "url", label = "@text/sendMessageActionInputURLLabel", description = "@text/sendMessageActionInputURLDescription", type = "java.lang.String") @Nullable String url,
+            @ActionInput(name = "urlTitle", label = "@text/sendMessageActionInputURLTitleLabel", description = "@text/sendMessageActionInputURLTitleDescription", type = "java.lang.String") @Nullable String urlTitle,
+            @ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String") @Nullable String attachment,
+            @ActionInput(name = "contentType", label = "@text/sendMessageActionInputContentTypeLabel", description = "@text/sendMessageActionInputContentTypeDescription", type = "java.lang.String", defaultValue = DEFAULT_CONTENT_TYPE) @Nullable String contentType,
+            @ActionInput(name = "priority", label = "@text/sendMessageActionInputPriorityLabel", description = "@text/sendMessageActionInputPriorityDescription", type = "java.lang.Integer", defaultValue = DEFAULT_EMERGENCY_PRIORITY) @Nullable Integer priority,
+            @ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String") @Nullable String device) {
+        logger.trace(
+                "ThingAction 'sendMessage' called with value(s): message='{}', title='{}', sound='{}', url='{}', urlTitle='{}', attachment='{}', contentType='{}', priority='{}', device='{}'",
+                message, title, sound, url, urlTitle, attachment, contentType, priority, device);
+
+        PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message);
+        if (sound != null) {
+            builder.withSound(sound);
+        }
+        if (url != null) {
+            builder.withUrl(url);
+            if (urlTitle != null) {
+                builder.withUrlTitle(urlTitle);
+            }
+        }
+        if (attachment != null) {
+            builder.withAttachment(attachment);
+            if (contentType != null) {
+                builder.withContentType(contentType);
+            }
+        }
+        if (priority != null) {
+            builder.withPriority(priority.intValue());
+        }
+        if (device != null) {
+            builder.withDevice(device);
+        }
+        return send(builder, title);
+    }
+
+    public static Boolean sendMessage(ThingActions actions, String message, @Nullable String title,
+            @Nullable String sound, @Nullable String url, @Nullable String urlTitle, @Nullable String attachment,
+            @Nullable String contentType, @Nullable Integer priority, @Nullable String device) {
+        return ((PushoverActions) actions).sendMessage(message, title, sound, url, urlTitle, attachment, contentType,
+                priority, device);
+    }
+
     @RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
     public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessage(
             @ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
index c6a3bf9a8470369779c792c68b9bb47c18339789..5e1bad241dfbbfaae46d49623ce90cda9aae334e 100644 (file)
@@ -19,6 +19,9 @@ sendMessageActionInputURLDescription = A supplementary URL to show with the mess
 sendMessageActionInputURLTitleLabel = URL Title
 sendMessageActionInputURLTitleDescription = A title for the URL, otherwise just the URL is shown.
 
+sendMessageActionInputSoundLabel = Sound
+sendMessageActionInputSoundDescription = The notification sound on target device.
+
 sendHTMLMessageActionLabel = send a HTML message
 sendHTMLMessageActionDescription = This method is used to send a HTML message.
 
index bcc86ce12c8a0e41970f72f64d5dacd39c717506..f340464ea0179b4f2f3cc5d28e89e40714b5f625 100644 (file)
@@ -35,6 +35,9 @@ sendMessageActionInputMessageDescription = Die Nachricht.
 sendMessageActionInputTitleLabel = Titel
 sendMessageActionInputTitleDescription = Titel der Nachricht.
 
+sendMessageActionInputSoundLabel = Benachrichtigungston
+sendMessageActionInputSoundDescription = Benachrichtigungston auf dem Endgerät.
+
 sendURLMessageActionLabel = eine Textnachricht mit URL senden
 sendURLMessageActionDescription = Action zum Versenden einer Textnachricht mit einer URL.
 sendMessageActionInputURLLabel = URL