4: Use severity in request to PushOver
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
# Asset Direction Target TRIGGER SEVERITY NOTE
|
||||
#############################################################
|
||||
SOL BELOW 170.0 ONETIME CRITICAL "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
|
||||
SOL BELOW 170.0 ONETIME INFO "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
|
||||
#SOL BELOW 71.4 ONETIME CRITICAL "CRITICAL: Risiko for Solana Raydium LÅN LIKVIDERING!"
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.r35157.jupiterperpsalarm;
|
||||
|
||||
public enum AlarmSeverity {
|
||||
EMERGENCY, // Repeated wake-up alarm
|
||||
CRITICAL, // One-shot wake-up alarm
|
||||
WARN, // Audible warning respecting quiet hours
|
||||
INFO, // Low-priority visible notification
|
||||
SILENT // No user interruption
|
||||
EMERGENCY, // Repeated wake-up alarm - sound always
|
||||
CRITICAL, // One-shot wake-up alarm - sound always
|
||||
WARN, // Audible warning - respecting quiet hours though
|
||||
INFO, // Normal notification with visual and audible feedback
|
||||
SILENT, // Low-priority notification - visual feedback without sound/vibration
|
||||
GHOST // No visual/audible notification - only visible inside the Pushover app
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.r35157.jupiterperpsalarm.impl.ref;
|
||||
|
||||
import com.r35157.jupiterperpsalarm.AlarmSeverity;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpClient;
|
||||
@@ -28,13 +30,13 @@ public final class PushoverAlarmAction implements AlarmAction {
|
||||
price.slot()
|
||||
);
|
||||
|
||||
// Severity and note are intentionally parsed and retained in the model,
|
||||
// but are not used by Pushover yet.
|
||||
// TODO: Note is intentionally parsed and retained in the model, but are not used by Pushover yet.
|
||||
// https://git.r35157.com/r35157/com_r35157_nenjim-hubd-impl_ref/issues/7
|
||||
String body = form("token", applicationToken) + "&" +
|
||||
form("user", userKey) + "&" +
|
||||
form("title", title) + "&" +
|
||||
form("message", message) + "&" +
|
||||
"priority=2&retry=30&expire=10800&sound=persistent";
|
||||
createPushoverSeverityParameters(alarm.severity());;
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder(PUSHOVER_URI)
|
||||
.timeout(Duration.ofSeconds(15))
|
||||
@@ -56,7 +58,7 @@ public final class PushoverAlarmAction implements AlarmAction {
|
||||
response.body()
|
||||
);
|
||||
} else {
|
||||
System.out.println("Pushover emergency alarm sent.");
|
||||
System.out.println("Pushover alarm sent: " + alarm.severity());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -66,6 +68,17 @@ public final class PushoverAlarmAction implements AlarmAction {
|
||||
URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String createPushoverSeverityParameters(AlarmSeverity severity) {
|
||||
return switch (severity) {
|
||||
case EMERGENCY -> "priority=2&retry=30&expire=10800&sound=persistent";
|
||||
case CRITICAL -> "priority=1&sound=spacealarm";
|
||||
case WARN -> "priority=0&sound=siren";
|
||||
case INFO -> "priority=0";
|
||||
case SILENT -> "priority=-1";
|
||||
case GHOST -> "priority=-2";
|
||||
};
|
||||
}
|
||||
|
||||
private final HttpClient httpClient = HttpClient.newHttpClient();
|
||||
private final String applicationToken;
|
||||
private final String userKey;
|
||||
|
||||
Reference in New Issue
Block a user