]> git.basschouten.com Git - openhab-addons.git/blob
ddfd14f43278ab35d37c81ca53c22fbfdff03a88
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.pushbullet.internal.action;
14
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.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {@link PushbulletActions} class defines rule actions for sending notifications
29  *
30  * @author Hakan Tandogan - Initial contribution
31  */
32 @ThingActionsScope(name = "pushbullet")
33 @NonNullByDefault
34 public class PushbulletActions implements ThingActions {
35
36     private final Logger logger = LoggerFactory.getLogger(PushbulletActions.class);
37
38     private @Nullable PushbulletHandler handler;
39
40     @Override
41     public void setThingHandler(@Nullable ThingHandler handler) {
42         this.handler = (PushbulletHandler) handler;
43     }
44
45     @Override
46     public @Nullable ThingHandler getThingHandler() {
47         return handler;
48     }
49
50     @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
51     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
52             @ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
53             @ActionInput(name = "title", label = "@text/actionSendPushbulletNoteInputTitleLabel", description = "@text/actionSendPushbulletNoteInputTitleDesc") @Nullable String title,
54             @ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
55         logger.trace("sendPushbulletNote '{}', '{}', '{}'", recipient, title, message);
56
57         PushbulletHandler localHandler = handler;
58         if (localHandler == null) {
59             logger.warn("Pushbullet service Handler is null!");
60             return false;
61         }
62
63         return localHandler.sendPush(recipient, title, message, "note");
64     }
65
66     public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient, @Nullable String title,
67             @Nullable String message) {
68         return ((PushbulletActions) actions).sendPushbulletNote(recipient, title, message);
69     }
70
71     @RuleAction(label = "@text/actionSendPushbulletNoteLabel", description = "@text/actionSendPushbulletNoteDesc")
72     public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPushbulletNote(
73             @ActionInput(name = "recipient", label = "@text/actionSendPushbulletNoteInputRecipientLabel", description = "@text/actionSendPushbulletNoteInputRecipientDesc") @Nullable String recipient,
74             @ActionInput(name = "message", label = "@text/actionSendPushbulletNoteInputMessageLabel", description = "@text/actionSendPushbulletNoteInputMessageDesc") @Nullable String message) {
75         logger.trace("sendPushbulletNote '{}', '{}'", recipient, message);
76
77         PushbulletHandler localHandler = handler;
78         if (localHandler == null) {
79             logger.warn("Pushbullet service Handler is null!");
80             return false;
81         }
82
83         return localHandler.sendPush(recipient, message, "note");
84     }
85
86     public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient,
87             @Nullable String message) {
88         return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
89     }
90 }