[prowl] Added the message priority setting feature (#12647)

Signed-off-by: Ondrej Pecta <opecta@gmail.com>
This commit is contained in:
Ondrej Pecta
2022-04-24 21:00:20 +02:00
committed by GitHub
parent 433ab4dcd4
commit ad71ca0055
6 changed files with 41 additions and 4 deletions

View 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();

View 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.");
}

View 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).

View 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).

View 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).