]> git.basschouten.com Git - openhab-addons.git/blob
79f5afd071d6444619e2c04430f449cbb2a138b3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.ServiceScope;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * The {@link PushbulletActions} class defines rule actions for sending notifications
31  *
32  * @author Hakan Tandogan - Initial contribution
33  */
34 @Component(scope = ServiceScope.PROTOTYPE, service = PushbulletActions.class)
35 @ThingActionsScope(name = "pushbullet")
36 @NonNullByDefault
37 public class PushbulletActions implements ThingActions {
38
39     private final Logger logger = LoggerFactory.getLogger(PushbulletActions.class);
40
41     private @Nullable PushbulletHandler handler;
42
43     @Override
44     public void setThingHandler(@Nullable ThingHandler handler) {
45         this.handler = (PushbulletHandler) handler;
46     }
47
48     @Override
49     public @Nullable ThingHandler getThingHandler() {
50         return handler;
51     }
52
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);
59
60         PushbulletHandler localHandler = handler;
61         if (localHandler == null) {
62             logger.warn("Pushbullet service Handler is null!");
63             return false;
64         }
65
66         return localHandler.sendPush(recipient, title, message, "note");
67     }
68
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);
72     }
73
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);
79
80         PushbulletHandler localHandler = handler;
81         if (localHandler == null) {
82             logger.warn("Pushbullet service Handler is null!");
83             return false;
84         }
85
86         return localHandler.sendPush(recipient, message, "note");
87     }
88
89     public static boolean sendPushbulletNote(ThingActions actions, @Nullable String recipient,
90             @Nullable String message) {
91         return ((PushbulletActions) actions).sendPushbulletNote(recipient, message);
92     }
93 }