2 * Copyright (c) 2010-2023 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.xmppclient.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.xmppclient.internal.XMPPClient;
18 import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler;
19 import org.openhab.core.automation.annotation.ActionInput;
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;
28 * This is the automation engine action handler service for the publishXMPP action.
30 * @author Pavel Gololobov - Initial contribution
32 @ThingActionsScope(name = "xmppclient")
34 public class XMPPActions implements ThingActions {
35 private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class);
36 private @Nullable XMPPClientHandler handler;
39 public void setThingHandler(@Nullable ThingHandler handler) {
40 this.handler = (XMPPClientHandler) handler;
44 public @Nullable ThingHandler getThingHandler() {
48 @RuleAction(label = "publish a message", description = "Publish a message using XMPP.")
49 public void publishXMPP(@ActionInput(name = "to", label = "To", description = "Send to") @Nullable String to,
50 @ActionInput(name = "text", label = "Text", description = "Message text") @Nullable String text) {
51 XMPPClientHandler clientHandler = handler;
52 if (clientHandler == null) {
53 logger.warn("XMPP ThingHandler is null");
57 XMPPClient connection = clientHandler.getXMPPClient();
58 if (connection == null) {
59 logger.warn("XMPP ThingHandler connection is null");
62 if ((to == null) || (text == null)) {
63 logger.info("Skipping XMPP messaging to {} value {}", to, text);
66 connection.sendMessage(to, text);
69 @RuleAction(label = "publish an image by HTTP", description = "Publish an image by HTTP using XMPP.")
70 public void publishXMPPImageByHTTP(
71 @ActionInput(name = "to", label = "To", description = "Send to") @Nullable String to,
72 @ActionInput(name = "filename", label = "Filename", description = "Image Filename") @Nullable String filename) {
73 XMPPClientHandler clientHandler = handler;
74 if (clientHandler == null) {
75 logger.warn("XMPP ThingHandler is null");
79 XMPPClient connection = clientHandler.getXMPPClient();
80 if (connection == null) {
81 logger.warn("XMPP ThingHandler connection is null");
84 if ((to == null) || (filename == null)) {
85 logger.warn("Skipping XMPP messaging to {} value {}", to, filename);
88 connection.sendImageByHTTP(to, filename);
91 public static void publishXMPP(ThingActions actions, @Nullable String to, @Nullable String text) {
92 ((XMPPActions) actions).publishXMPP(to, text);
95 public static void publishXMPPImageByHTTP(ThingActions actions, @Nullable String to, @Nullable String filename) {
96 ((XMPPActions) actions).publishXMPPImageByHTTP(to, filename);