## Thing Actions
All actions return a `Boolean` value to indicate if the message was sent successfully or not.
+If the communication to Pushover servers fails the binding does not try to send the message again.
+One has to take care of that on its own if it is important.
The parameter `message` is **mandatory**, the `title` parameter defaults to whatever value you defined in the `title` related configuration parameter.
Parameters declared as `@Nullable` are not optional.
One has to pass a `null` value if it should be skipped or the default value for it should be used.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
return executeRequest(HttpMethod.POST, url, body);
}
- private String executeRequest(HttpMethod httpMethod, String url, @Nullable ContentProvider body)
+ private synchronized String executeRequest(HttpMethod httpMethod, String url, @Nullable ContentProvider body)
throws PushoverCommunicationException, PushoverConfigurationException {
logger.trace("Pushover request: {} - URL = '{}'", httpMethod, url);
try {
private String getMessageError(String content) {
final JsonObject json = JsonParser.parseString(content).getAsJsonObject();
- if (json.has("errors")) {
- final JsonArray errors = json.get("errors").getAsJsonArray();
- if (errors != null) {
- return errors.toString();
- }
+ final JsonElement errorsElement = json.get("errors");
+ if (errorsElement != null && errorsElement.isJsonArray()) {
+ return errorsElement.getAsJsonArray().toString();
}
- return "Unknown error occured.";
+ return "@text/offline.conf-error-unknown";
}
private boolean getMessageStatus(String content) {
import org.osgi.service.component.annotations.Reference;
/**
- * The {@link PushoverHandlerFactory} is responsible for creating things and thing
- * handlers.
+ * The {@link PushoverHandlerFactory} is responsible for creating things and thing handlers.
*
* @author Christoph Weitkamp - Initial contribution
*/
public boolean sendMessage(PushoverMessageBuilder messageBuilder) {
if (connection != null) {
- return connection.sendMessage(messageBuilder);
+ try {
+ return connection.sendMessage(messageBuilder);
+ } catch (PushoverCommunicationException e) {
+ // do nothing, causing exception is already logged
+ } catch (PushoverConfigurationException e) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
+ }
+ return false;
} else {
throw new IllegalArgumentException("PushoverAPIConnection is null!");
}
public String sendPriorityMessage(PushoverMessageBuilder messageBuilder) {
if (connection != null) {
- return connection.sendPriorityMessage(messageBuilder);
+ try {
+ return connection.sendPriorityMessage(messageBuilder);
+ } catch (PushoverCommunicationException e) {
+ // do nothing, causing exception is already logged
+ } catch (PushoverConfigurationException e) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
+ }
+ return "";
} else {
throw new IllegalArgumentException("PushoverAPIConnection is null!");
}
public boolean cancelPriorityMessage(String receipt) {
if (connection != null) {
- return connection.cancelPriorityMessage(receipt);
+ try {
+ return connection.cancelPriorityMessage(receipt);
+ } catch (PushoverCommunicationException e) {
+ // do nothing, causing exception is already logged
+ } catch (PushoverConfigurationException e) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
+ }
+ return false;
} else {
throw new IllegalArgumentException("PushoverAPIConnection is null!");
}
}
+ @SuppressWarnings("null")
private void asyncValidateUser() {
try {
connection.validateUser();
# user defined messages
offline.conf-error-missing-apikey = The 'apikey' parameter must be configured.
offline.conf-error-missing-user = The 'user' parameter must be configured.
+offline.conf-error-unknown = An unknown error occurred.
# actions
sendMessageActionLabel = send a plain text message
# user defined messages
offline.conf-error-missing-apikey = Der Parameter 'apikey' muss konfiguriert werden.
offline.conf-error-missing-user = Der Parameter 'user' muss konfiguriert werden.
+offline.conf-error-unknown = Ein unbekannter Fehler ist aufgetreten.
# actions
sendMessageActionLabel = eine Textnachricht senden