2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.pushbullet.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.pushbullet.internal.handler.PushbulletHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.ActionOutput;
20 import org.openhab.core.automation.annotation.RuleAction;
21 import org.openhab.core.thing.binding.ThingActions;
22 import org.openhab.core.thing.binding.ThingActionsScope;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.ServiceScope;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * The {@link PushbulletActions} class defines rule actions for sending notifications
32 * @author Hakan Tandogan - Initial contribution
34 @Component(scope = ServiceScope.PROTOTYPE, service = PushbulletActions.class)
35 @ThingActionsScope(name = "pushbullet")
37 public class PushbulletActions implements ThingActions {
39 private final Logger logger = LoggerFactory.getLogger(PushbulletActions.class);
41 private @Nullable PushbulletHandler handler;
44 public void setThingHandler(@Nullable ThingHandler handler) {
45 this.handler = (PushbulletHandler) handler;
49 public @Nullable ThingHandler getThingHandler() {
53 @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
54 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
55 @ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
56 @ActionInput(name = "title", label = "@text/actionSendPushbulletNoteInputTitleLabel", description = "@text/actionSendPushbulletNoteInputTitleDesc") @Nullable String title,
57 @ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
58 logger.trace("sendPushbulletNote '{}', '{}', '{}'", recipient, title, message);
60 PushbulletHandler localHandler = handler;
61 if (localHandler == null) {
62 logger.warn("Pushbullet service Handler is null!");
66 return localHandler.sendPush(recipient, title, message, "note");
69 public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient, @Nullable String title,
70 @Nullable String message) {
71 return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
74 @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
75 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
76 @ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
77 @ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
78 logger.trace("sendPushbulletNote '{}', '{}'", recipient, message);
80 PushbulletHandler localHandler = handler;
81 if (localHandler == null) {
82 logger.warn("Pushbullet service Handler is null!");
86 return localHandler.sendPush(recipient, message, "note");
89 public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient,
90 @Nullable String message) {
91 return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);