## Thing Configuration
-| Configuration Parameter | Type | Description |
-|-------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `apikey` | text | Your API token / key (APP_TOKEN) to access the Pushover Message API. **mandatory** |
-| `user` | text | Your user key or group key (USER_KEY) to which you want to push notifications. **mandatory** |
-| `title` | text | The default title of a message (default: `openHAB`). |
-| `format` | text | The default format (`none`, `html` or `monospace`) of a message (default: `none`). |
-| `sound` | text | The default notification sound on target device (default: `default`) (see [supported notification sounds](https://pushover.net/api#sounds)). |
-| `retry` | integer | The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user (default: `300`). **advanced** |
-| `expire` | integer | The expire parameter specifies how long (in seconds) your notification will continue to be retried (default: `3600`). **advanced** |
-| `timeout` | integer | The timeout parameter specifies maximum number of seconds a request to Pushover can take. **advanced** |
+| Configuration Parameter | Type | Description |
+|-------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `apikey` | text | Your API token / key (APP_TOKEN) to access the Pushover Message API. **mandatory** |
+| `user` | text | Your user key or group key (USER_KEY) to which you want to push notifications. **mandatory** |
+| `title` | text | The default title of a message (default: `openHAB`). |
+| `format` | text | The default format (`none`, `html` or `monospace`) of a message (default: `none`). |
+| `sound` | text | The notification sound on target device (default: `default`) (see [supported notification sounds](https://pushover.net/api#sounds)). This list will be populated dynamically during runtime with 21 different sounds plus user-defined [custom sounds](https://blog.pushover.net/posts/2021/3/custom-sounds). |
+| `retry` | integer | The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user (default: `300`). **advanced** |
+| `expire` | integer | The expire parameter specifies how long (in seconds) your notification will continue to be retried (default: `3600`). **advanced** |
+| `timeout` | integer | The timeout parameter specifies maximum number of seconds a request to Pushover can take. **advanced** |
The `retry` and `expire` parameters are only used for emergency-priority notifications.
message, title, sound, url, urlTitle, attachment, contentType, priority, device);
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message);
- if (sound != null) {
+ // add sound, if defined
+ if (sound != null && !DEFAULT_SOUND.equals(sound)) {
builder.withSound(sound);
}
if (url != null) {
import static org.openhab.binding.pushover.internal.PushoverBindingConstants.*;
+import java.util.List;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.pushover.internal.dto.Sound;
/**
* The {@link PushoverAccountConfiguration} class contains fields mapping thing configuration parameters.
*/
@NonNullByDefault
public class PushoverAccountConfiguration {
+ public static final List<Sound> 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"),
+ new Sound("falling", "Falling"), new Sound("gamelan", "Gamelan"), new Sound("incoming", "Incoming"),
+ new Sound("intermission", "Intermission"), new Sound("magic", "Magic"),
+ new Sound("mechanical", "Mechanical"), new Sound("none", "None (silent)"),
+ 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"));
+
public @Nullable String apikey;
public @Nullable String user;
public String title = DEFAULT_TITLE;
@Override
public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
@Nullable Locale locale) {
- if (accountHandler != null && PUSHOVER_ACCOUNT.getAsString().equals(uri.getSchemeSpecificPart())
+ PushoverAccountHandler localAccountHandler = accountHandler;
+ if (localAccountHandler != null && PUSHOVER_ACCOUNT.getAsString().equals(uri.getSchemeSpecificPart())
&& CONFIG_SOUND.equals(param)) {
- List<Sound> sounds = accountHandler.getSounds();
+ List<Sound> sounds = localAccountHandler.getSounds();
if (!sounds.isEmpty()) {
return sounds.stream().map(Sound::getAsParameterOption)
.sorted(Comparator.comparing(ParameterOption::getLabel))
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
final JsonObject sounds = json == null || !json.has("sounds") ? null : json.get("sounds").getAsJsonObject();
return sounds == null ? List.of()
- : Collections.unmodifiableList(sounds.entrySet().stream()
- .map(entry -> new Sound(entry.getKey(), entry.getValue().getAsString()))
- .collect(Collectors.toList()));
+ : sounds.entrySet().stream().map(entry -> new Sound(entry.getKey(), entry.getValue().getAsString()))
+ .collect(Collectors.toUnmodifiableList());
}
private String buildURL(String url, Map<String, String> requestParams) {
return this;
}
- public ContentProvider build() {
+ public ContentProvider build() throws PushoverCommunicationException {
if (message != null) {
if (message.length() > MAX_MESSAGE_LENGTH) {
throw new IllegalArgumentException(String.format(
body.addFilePart(MESSAGE_KEY_ATTACHMENT, file.getName(),
new PathContentProvider(contentType, file.toPath()), null);
} catch (IOException e) {
- throw new IllegalArgumentException(String.format("Skip sending the message: %s", e.getMessage()));
+ logger.debug("IOException occurred - skip sending message: {}", e.getLocalizedMessage(), e);
+ throw new PushoverCommunicationException(
+ String.format("Skip sending the message: %s", e.getLocalizedMessage()), e);
}
}
private final HttpClient httpClient;
- private @NonNullByDefault({}) PushoverAccountConfiguration config;
+ private PushoverAccountConfiguration config = new PushoverAccountConfiguration();
private @Nullable PushoverAPIConnection connection;
public PushoverAccountHandler(Thing thing, HttpClient httpClient) {
* @return a list of {@link Sound}s
*/
public List<Sound> getSounds() {
- return connection != null ? connection.getSounds() : List.of();
+ try {
+ return connection != null ? connection.getSounds() : PushoverAccountConfiguration.DEFAULT_SOUNDS;
+ } catch (PushoverCommunicationException e) {
+ // do nothing, causing exception is already logged
+ } catch (PushoverConfigurationException e) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
+ }
+ return PushoverAccountConfiguration.DEFAULT_SOUNDS;
}
/**
default:
break;
}
- // add sound if defined
+ // add sound, if defined
if (!DEFAULT_SOUND.equals(config.sound)) {
builder.withSound(config.sound);
}
</parameter>
<parameter name="sound" type="text">
<label>Notification Sound</label>
- <description>The default notification sound on target device.</description>
+ <description>The notification sound on target device.</description>
<default>default</default>
</parameter>
<parameter name="retry" type="integer" min="30" unit="s">
thing-type.config.pushover.pushover-account.format.label = Format
thing-type.config.pushover.pushover-account.format.description = Standardformat der Nachricht.
thing-type.config.pushover.pushover-account.sound.label = Benachrichtigungston
-thing-type.config.pushover.pushover-account.sound.description = Standardbenachrichtigungston auf dem Endgerät.
+thing-type.config.pushover.pushover-account.sound.description = Benachrichtigungston auf dem Endgerät.
thing-type.config.pushover.pushover-account.retry.label = Wiederholungen
thing-type.config.pushover.pushover-account.retry.description = Dieser Parameter gibt an, in welchen Abständen eine Prioritätsnachricht wiederholt an den Benutzer gesendet werden soll.
thing-type.config.pushover.pushover-account.expire.label = Verfall
thing-type.config.pushover.pushover-account.expire.description = Dieser Parameter gibt an, wie lange eine Prioritätsnachricht wiederholt wird.
+thing-type.config.pushover.pushover-account.timeout.label = Timeout
+thing-type.config.pushover.pushover-account.timeout.description = Dieser Parameter gibt an, wie lange eine Anfrage an die Pushover Message API maximal dauern darf.
# user defined messages
offline.conf-error-missing-apikey = Der Parameter 'apikey' muss konfiguriert werden.