From b5e480bd30cb75c132ab345c1eb517b5401abe2a Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Thu, 17 Feb 2022 23:03:31 +0100 Subject: [PATCH] Allow default sound parameter value (#12309) Signed-off-by: Christoph Weitkamp --- .../internal/config/PushoverAccountConfiguration.java | 3 ++- .../internal/connection/PushoverAPIConnection.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/config/PushoverAccountConfiguration.java b/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/config/PushoverAccountConfiguration.java index 721e45cf2e0..9f059494192 100644 --- a/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/config/PushoverAccountConfiguration.java +++ b/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/config/PushoverAccountConfiguration.java @@ -27,6 +27,7 @@ import org.openhab.binding.pushover.internal.dto.Sound; */ @NonNullByDefault public class PushoverAccountConfiguration { + public static final Sound SOUND_DEFAULT = new Sound("default", "Default"); public static final List DEFAULT_SOUNDS = List.of(new Sound("alien", "Alien Alarm (long)"), new Sound("bike", "Bike"), new Sound("bugle", "Bugle"), new Sound("cashregister", "Cash Register"), new Sound("classical", "Classical"), new Sound("climb", "Climb (long)"), new Sound("cosmic", "Cosmic"), @@ -36,7 +37,7 @@ public class PushoverAccountConfiguration { new Sound("persistent", "Persistent (long)"), new Sound("pianobar", "Piano Bar"), new Sound("pushover", "Pushover (default)"), new Sound("echo", "Pushover Echo (long)"), new Sound("siren", "Siren"), new Sound("spacealarm", "Space Alarm"), new Sound("tugboat", "Tug Boat"), - new Sound("updown", "Up Down (long)"), new Sound("vibrate", "Vibrate Only")); + new Sound("updown", "Up Down (long)"), new Sound("vibrate", "Vibrate Only"), SOUND_DEFAULT); public @Nullable String apikey; public @Nullable String user; diff --git a/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/connection/PushoverAPIConnection.java b/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/connection/PushoverAPIConnection.java index 2c9d756381a..7ba8676f3f9 100644 --- a/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/connection/PushoverAPIConnection.java +++ b/bundles/org.openhab.binding.pushover/src/main/java/org/openhab/binding/pushover/internal/connection/PushoverAPIConnection.java @@ -109,12 +109,14 @@ public class PushoverAPIConnection { final String content = get( buildURL(SOUNDS_URL, Map.of(PushoverMessageBuilder.MESSAGE_KEY_TOKEN, localApikey))); final JsonObject json = JsonParser.parseString(content).getAsJsonObject(); - final JsonObject sounds = json.has(JSON_VALUE_SOUNDS) ? json.get(JSON_VALUE_SOUNDS).getAsJsonObject() + final JsonObject jsonSounds = json.has(JSON_VALUE_SOUNDS) ? json.get(JSON_VALUE_SOUNDS).getAsJsonObject() : null; - if (sounds != null) { - return sounds.entrySet().stream() + if (jsonSounds != null) { + List sounds = jsonSounds.entrySet().stream() .map(entry -> new Sound(entry.getKey(), entry.getValue().getAsString())) - .collect(Collectors.toUnmodifiableList()); + .collect(Collectors.toList()); + sounds.add(PushoverAccountConfiguration.SOUND_DEFAULT); + return sounds; } } catch (JsonSyntaxException e) { // do nothing