]> git.basschouten.com Git - openhab-addons.git/commitdiff
[prowl] Added the message priority setting feature (#12647)
authorOndrej Pecta <opecta@gmail.com>
Sun, 24 Apr 2022 19:00:20 +0000 (21:00 +0200)
committerGitHub <noreply@github.com>
Sun, 24 Apr 2022 19:00:20 +0000 (21:00 +0200)
Signed-off-by: Ondrej Pecta <opecta@gmail.com>
bundles/org.openhab.binding.prowl/README.md
bundles/org.openhab.binding.prowl/src/main/java/org/openhab/binding/prowl/internal/ProwlHandler.java
bundles/org.openhab.binding.prowl/src/main/java/org/openhab/binding/prowl/internal/action/ProwlActions.java
bundles/org.openhab.binding.prowl/src/main/resources/OH-INF/i18n/prowl.properties
bundles/org.openhab.binding.prowl/src/main/resources/OH-INF/i18n/prowl_fr.properties
bundles/org.openhab.binding.prowl/src/main/resources/OH-INF/i18n/prowl_it.properties

index 34ac1981df04fe58bc55e904a18832f57eab320c..a0519d2999c54767b33c28e1f468a6ffeeb5ca4e 100644 (file)
@@ -35,9 +35,11 @@ _*.rules_
 
 Once you have created the broker thing with a valid API key, you can use the Prowl service in your rules.  
 First you need to create an instance of the broker just before any call or on the top rules level. (replace the _mybroker_ with the right name of your instance).
-Then you can call method _pushNotification_, which requires two parameters - _event_ and _description_.  
+Then you can call method _pushNotification_, which requires two parameters - _event_ and _description_. 
+There is also an optional third parameter _priority_ which represents the message priority (very low) -2,-1,0,1,2 (emergency). The default priority is 0. 
 
 ```
 val prowl = getActions("prowl","prowl:broker:mybroker")  
 prowl.pushNotification("Event", "This is the description of the event")
+prowl.pushNotification("Emergency Event", "This is the description of the event", 2)
 ```
index 6ba26fb0476a4c7cab63cf9dfe3bacee0c3e31e4..f292fa165305dbf2c9a89e2513501e803c36d871 100644 (file)
@@ -49,7 +49,7 @@ public class ProwlHandler extends BaseThingHandler {
     private final Logger logger = LoggerFactory.getLogger(ProwlHandler.class);
 
     private ProwlConfiguration config = new ProwlConfiguration();
-    final private HttpClient httpClient;
+    private final HttpClient httpClient;
 
     /**
      * Future to poll for status
@@ -117,17 +117,27 @@ public class ProwlHandler extends BaseThingHandler {
     }
 
     public void pushNotification(@Nullable String event, @Nullable String description) {
+        pushNotification(event, description, 0);
+    }
+
+    public void pushNotification(@Nullable String event, @Nullable String description, int priority) {
         if (event == null || description == null) {
             logger.debug("Cannot push message with null event or null description");
             return;
         }
 
+        if (priority < -2) {
+            priority = -2;
+        } else if (priority > 2) {
+            priority = 2;
+        }
+
         logger.debug("Pushing an event: {} with desc: {}", event, description);
         try {
             ContentResponse response = httpClient.POST(PROWL_ADD_URI).timeout(5, TimeUnit.SECONDS)
                     .content(
                             new StringContentProvider("apikey=" + config.apiKey + "&application=" + config.application
-                                    + "&event=" + event + "&description=" + description),
+                                    + "&event=" + event + "&description=" + description + "&priority=" + priority),
                             "application/x-www-form-urlencoded; charset=UTF-8")
                     .send();
             String resp = response.getContentAsString();
index a535caf52e689406099a2b0305d22c50928fa9b6..df7dda12ead85c4fca5f80a56fe23be999d559e0 100644 (file)
@@ -57,10 +57,29 @@ public class ProwlActions implements ThingActions {
         handler.pushNotification(event, message);
     }
 
+    @RuleAction(label = "@text/pushNotificationActionLabel", description = "@text/pushNotificationActionDescription")
+    public void pushNotification(
+            @ActionInput(name = "event", label = "@text/pushNotificationActionEventLabel", description = "@text/pushNotificationActionEventDescription") @Nullable String event,
+            @ActionInput(name = "message", label = "@text/pushNotificationActionMessageLabel", description = "@text/pushNotificationActionMessageDescription") @Nullable String message,
+            @ActionInput(name = "priority", label = "@text/pushNotificationActionPriorityLabel", description = "@text/pushNotificationActionPriorityDescription") int priority) {
+        ProwlHandler clientHandler = handler;
+        if (clientHandler == null) {
+            logger.warn("Prowl ThingHandler is null");
+            return;
+        }
+
+        handler.pushNotification(event, message, priority);
+    }
+
     public static void pushNotification(@Nullable ThingActions actions, @Nullable String event,
             @Nullable String description) {
+        pushNotification(actions, event, description, 0);
+    }
+
+    public static void pushNotification(@Nullable ThingActions actions, @Nullable String event,
+            @Nullable String description, int priority) {
         if (actions instanceof ProwlActions) {
-            ((ProwlActions) actions).pushNotification(event, description);
+            ((ProwlActions) actions).pushNotification(event, description, priority);
         } else {
             throw new IllegalArgumentException("Instance is not a ProwlActions class.");
         }
index 08d7fb8c6bb0a4214c83fc7ddd3fd1fb86324ac9..24a30415054747375449440f42325bf8615a8f20 100644 (file)
@@ -30,3 +30,5 @@ pushNotificationActionEventLabel = Event
 pushNotificationActionEventDescription = Event name.
 pushNotificationActionMessageLabel = Message
 pushNotificationActionMessageDescription = Message text.
+pushNotificationActionPriorityLabel = Priority
+pushNotificationActionPriorityDescription = Message priority (-2,-1,0,1,2).
index 09e5e9be7e40f383397f2ec36e5a647bbbd3c5c8..4ba33c1227194fddc902026aa216dee3998eb7c1 100644 (file)
@@ -30,3 +30,5 @@ pushNotificationActionEventLabel = Evénement
 pushNotificationActionEventDescription = Nom de l'événement.
 pushNotificationActionMessageLabel = Message
 pushNotificationActionMessageDescription = Texte du message.
+pushNotificationActionPriorityLabel = Priorité
+pushNotificationActionPriorityDescription = Priorité du message (-2,-1,0,1,2).
index b6dd757da92c52d4e471d789b41476d3581b5b0e..cdebe2b70d63600923c2fe5688b8f9224d45a77a 100644 (file)
@@ -30,3 +30,5 @@ pushNotificationActionEventLabel = Evento
 pushNotificationActionEventDescription = Nome evento.
 pushNotificationActionMessageLabel = Messaggio
 pushNotificationActionMessageDescription = Testo del messaggio.
+pushNotificationActionPriorityLabel = Priorità
+pushNotificationActionPriorityDescription = Priorità del messaggio (-2,-1,0,1,2).