|
|
|
@ -15,6 +15,8 @@ package org.openhab.binding.pushover.internal.actions;
|
|
|
|
|
import static org.openhab.binding.pushover.internal.PushoverBindingConstants.*;
|
|
|
|
|
import static org.openhab.binding.pushover.internal.connection.PushoverMessageBuilder.*;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
|
|
|
|
import org.eclipse.jdt.annotation.Nullable;
|
|
|
|
|
import org.openhab.binding.pushover.internal.connection.PushoverMessageBuilder;
|
|
|
|
@ -32,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
* Some automation actions to be used with a {@link PushoverAccountHandler}.
|
|
|
|
|
*
|
|
|
|
|
* @author Christoph Weitkamp - Initial contribution
|
|
|
|
|
* @author Jacob Laursen - Added support for Expiring Messages
|
|
|
|
|
*/
|
|
|
|
|
@ThingActionsScope(name = "pushover")
|
|
|
|
|
@NonNullByDefault
|
|
|
|
@ -53,7 +56,8 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
@ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String") @Nullable String attachment,
|
|
|
|
|
@ActionInput(name = "contentType", label = "@text/sendMessageActionInputContentTypeLabel", description = "@text/sendMessageActionInputContentTypeDescription", type = "java.lang.String", defaultValue = DEFAULT_CONTENT_TYPE) @Nullable String contentType,
|
|
|
|
|
@ActionInput(name = "priority", label = "@text/sendMessageActionInputPriorityLabel", description = "@text/sendMessageActionInputPriorityDescription", type = "java.lang.Integer", defaultValue = DEFAULT_EMERGENCY_PRIORITY) @Nullable Integer priority,
|
|
|
|
|
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String") @Nullable String device) {
|
|
|
|
|
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String") @Nullable String device,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendMessage' called with value(s): message='{}', title='{}', sound='{}', url='{}', urlTitle='{}', attachment='{}', contentType='{}', priority='{}', device='{}'",
|
|
|
|
|
message, title, sound, url, urlTitle, attachment, contentType, priority, device);
|
|
|
|
@ -81,14 +85,28 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
if (device != null) {
|
|
|
|
|
builder.withDevice(device);
|
|
|
|
|
}
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessage(ThingActions actions, String message, @Nullable String title,
|
|
|
|
|
@Nullable String sound, @Nullable String url, @Nullable String urlTitle, @Nullable String attachment,
|
|
|
|
|
@Nullable String contentType, @Nullable Integer priority, @Nullable String device) {
|
|
|
|
|
@Nullable String contentType, @Nullable Integer priority, @Nullable String device, @Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendMessage(message, title, sound, url, urlTitle, attachment, contentType,
|
|
|
|
|
priority, device);
|
|
|
|
|
priority, device, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message) {
|
|
|
|
|
logger.trace("ThingAction 'sendMessage' called with value(s): message='{}'", message);
|
|
|
|
|
return send(getDefaultPushoverMessageBuilder(message), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessage(ThingActions actions, String message) {
|
|
|
|
|
return ((PushoverActions) actions).sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
|
|
|
|
@ -103,11 +121,30 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendMessage(message, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace("ThingAction 'sendMessage' called with value(s): message='{}', title='{}', ttl='{}'", message,
|
|
|
|
|
title, ttl);
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message);
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessage(ThingActions actions, String message, @Nullable String title,
|
|
|
|
|
@Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendMessage(message, title, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendURLMessageActionLabel", description = "@text/sendURLMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendURLMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "url", label = "@text/sendMessageActionInputURLLabel", description = "@text/sendMessageActionInputURLDescription", type = "java.lang.String", required = true) String url,
|
|
|
|
|
@ActionInput(name = "url", label = "@text/sendMessageActionInputURLLabel", description = "@text/sendMessageActionInputURLDescription", type = "java.lang.String", required = true) @Nullable String url,
|
|
|
|
|
@ActionInput(name = "urlTitle", label = "@text/sendMessageActionInputURLTitleLabel", description = "@text/sendMessageActionInputURLTitleDescription", type = "java.lang.String") @Nullable String urlTitle) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendURLMessage' called with value(s): message='{}', url='{}', title='{}', urlTitle='{}'",
|
|
|
|
@ -128,6 +165,35 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendURLMessage(message, title, url, urlTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendURLMessageActionLabel", description = "@text/sendURLMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendURLMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "url", label = "@text/sendMessageActionInputURLLabel", description = "@text/sendMessageActionInputURLDescription", type = "java.lang.String", required = true) @Nullable String url,
|
|
|
|
|
@ActionInput(name = "urlTitle", label = "@text/sendMessageActionInputURLTitleLabel", description = "@text/sendMessageActionInputURLTitleDescription", type = "java.lang.String") @Nullable String urlTitle,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendURLMessage' called with value(s): message='{}', url='{}', title='{}', urlTitle='{}', ttl='{}'",
|
|
|
|
|
message, url, title, urlTitle, ttl);
|
|
|
|
|
if (url == null) {
|
|
|
|
|
throw new IllegalArgumentException("Skip sending message as 'url' is null.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withUrl(url);
|
|
|
|
|
if (urlTitle != null) {
|
|
|
|
|
builder.withUrl(urlTitle);
|
|
|
|
|
}
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendURLMessage(ThingActions actions, String message, @Nullable String title, String url,
|
|
|
|
|
@Nullable String urlTitle, @Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendURLMessage(message, title, url, urlTitle, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendHtmlMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
@ -140,6 +206,25 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendHtmlMessage(message, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendHtmlMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace("ThingAction 'sendHtmlMessage' called with value(s): message='{}', title='{}', ttl='{}'", message,
|
|
|
|
|
title, ttl);
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withHtmlFormatting();
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendHtmlMessage(ThingActions actions, String message, @Nullable String title,
|
|
|
|
|
@Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendHtmlMessage(message, title, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMonospaceMessageActionLabel", description = "@text/sendMonospaceMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMonospaceMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
@ -153,11 +238,30 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendMonospaceMessage(message, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMonospaceMessageActionLabel", description = "@text/sendMonospaceMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMonospaceMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace("ThingAction 'sendMonospaceMessage' called with value(s): message='{}', title='{}', ttl='{}'",
|
|
|
|
|
message, title, ttl);
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withMonospaceFormatting();
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMonospaceMessage(ThingActions actions, String message, @Nullable String title,
|
|
|
|
|
@Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendMonospaceMessage(message, title, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendAttachmentMessageActionLabel", description = "@text/sendAttachmentMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendAttachmentMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String", required = true) String attachment,
|
|
|
|
|
@ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String", required = true) @Nullable String attachment,
|
|
|
|
|
@ActionInput(name = "contentType", label = "@text/sendMessageActionInputContentTypeLabel", description = "@text/sendMessageActionInputContentTypeDescription", type = "java.lang.String", defaultValue = DEFAULT_CONTENT_TYPE) @Nullable String contentType) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendAttachmentMessage' called with value(s): message='{}', title='{}', attachment='{}', contentType='{}'",
|
|
|
|
@ -178,6 +282,35 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendAttachmentMessage(message, title, attachment, contentType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendAttachmentMessageActionLabel", description = "@text/sendAttachmentMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendAttachmentMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "attachment", label = "@text/sendMessageActionInputAttachmentLabel", description = "@text/sendMessageActionInputAttachmentDescription", type = "java.lang.String", required = true) @Nullable String attachment,
|
|
|
|
|
@ActionInput(name = "contentType", label = "@text/sendMessageActionInputContentTypeLabel", description = "@text/sendMessageActionInputContentTypeDescription", type = "java.lang.String", defaultValue = DEFAULT_CONTENT_TYPE) @Nullable String contentType,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendAttachmentMessage' called with value(s): message='{}', title='{}', attachment='{}', contentType='{}', ttl='{}'",
|
|
|
|
|
message, title, attachment, contentType, ttl);
|
|
|
|
|
if (attachment == null) {
|
|
|
|
|
throw new IllegalArgumentException("Skip sending message as 'attachment' is null.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withAttachment(attachment);
|
|
|
|
|
if (contentType != null) {
|
|
|
|
|
builder.withContentType(contentType);
|
|
|
|
|
}
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendAttachmentMessage(ThingActions actions, String message, @Nullable String title,
|
|
|
|
|
String attachment, @Nullable String contentType, @Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendAttachmentMessage(message, title, attachment, contentType, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendPriorityMessageActionLabel", description = "@text/sendPriorityMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "receipt", label = "@text/sendPriorityMessageActionOutputLabel", description = "@text/sendPriorityMessageActionOutputDescription", type = "java.lang.String") String sendPriorityMessage(
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
@ -201,10 +334,10 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/cancelPriorityMessageActionLabel", description = "@text/cancelPriorityMessageActionDescription")
|
|
|
|
|
public @ActionOutput(name = "canceled", label = "@text/cancelPriorityMessageActionOutputLabel", description = "@text/cancelPriorityMessageActionOutputDescription", type = "java.lang.Boolean") Boolean cancelPriorityMessage(
|
|
|
|
|
@ActionInput(name = "receipt", label = "@text/cancelPriorityMessageActionInputReceiptLabel", description = "@text/cancelPriorityMessageActionInputReceiptDescription", type = "java.lang.String", required = true) String receipt) {
|
|
|
|
|
@ActionInput(name = "receipt", label = "@text/cancelPriorityMessageActionInputReceiptLabel", description = "@text/cancelPriorityMessageActionInputReceiptDescription", type = "java.lang.String", required = true) @Nullable String receipt) {
|
|
|
|
|
logger.trace("ThingAction 'cancelPriorityMessage' called with value(s): '{}'", receipt);
|
|
|
|
|
if (accountHandler == null) {
|
|
|
|
|
throw new RuntimeException("PushoverAccountHandler is null!");
|
|
|
|
|
throw new IllegalStateException("PushoverAccountHandler is null!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (receipt == null) {
|
|
|
|
@ -220,7 +353,7 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
|
|
|
|
|
@RuleAction(label = "@text/sendMessageToDeviceActionLabel", description = "@text/sendMessageToDeviceActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessageToDevice(
|
|
|
|
|
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String", required = true) String device,
|
|
|
|
|
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String", required = true) @Nullable String device,
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title) {
|
|
|
|
|
logger.trace("ThingAction 'sendMessageToDevice' called with value(s): device='{}', message='{}', title='{}'",
|
|
|
|
@ -237,9 +370,34 @@ public class PushoverActions implements ThingActions {
|
|
|
|
|
return ((PushoverActions) actions).sendMessageToDevice(device, message, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PushoverMessageBuilder getDefaultPushoverMessageBuilder(String message) {
|
|
|
|
|
@RuleAction(label = "@text/sendMessageToDeviceActionLabel", description = "@text/sendMessageToDeviceActionDescription")
|
|
|
|
|
public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendMessageToDevice(
|
|
|
|
|
@ActionInput(name = "device", label = "@text/sendMessageActionInputDeviceLabel", description = "@text/sendMessageActionInputDeviceDescription", type = "java.lang.String", required = true) @Nullable String device,
|
|
|
|
|
@ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
|
|
|
|
|
@ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String", defaultValue = DEFAULT_TITLE) @Nullable String title,
|
|
|
|
|
@ActionInput(name = "ttl", label = "@text/sendMessageActionInputTTLLabel", description = "@text/sendMessageActionInputTTLDescription", type = "java.time.Duration") @Nullable Duration ttl) {
|
|
|
|
|
logger.trace(
|
|
|
|
|
"ThingAction 'sendMessageToDevice' called with value(s): device='{}', message='{}', title='{}', ttl='{}'",
|
|
|
|
|
device, message, title, ttl);
|
|
|
|
|
if (device == null) {
|
|
|
|
|
throw new IllegalArgumentException("Skip sending message as 'device' is null.");
|
|
|
|
|
}
|
|
|
|
|
PushoverMessageBuilder builder = getDefaultPushoverMessageBuilder(message).withDevice(device);
|
|
|
|
|
if (ttl != null) {
|
|
|
|
|
builder.withTTL(ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return send(builder, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean sendMessageToDevice(ThingActions actions, String device, String message,
|
|
|
|
|
@Nullable String title, @Nullable Duration ttl) {
|
|
|
|
|
return ((PushoverActions) actions).sendMessageToDevice(device, message, title, ttl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PushoverMessageBuilder getDefaultPushoverMessageBuilder(@Nullable String message) {
|
|
|
|
|
if (accountHandler == null) {
|
|
|
|
|
throw new RuntimeException("PushoverAccountHandler is null!");
|
|
|
|
|
throw new IllegalStateException("PushoverAccountHandler is null!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message == null) {
|
|
|
|
|