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.handler;
15 import org.openhab.binding.xmppclient.internal.XMPPClient;
16 import org.openhab.core.thing.ChannelUID;
19 * Subscribes to a chat and calls
20 * {@link org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler#triggerChannel(ChannelUID, String)} if a
21 * value has been received.
23 * @author Pavel Gololobov - Initial contribution
25 public class PublishTriggerChannel implements XMPPClientMessageSubscriber {
26 private final XMPPClient connection;
27 private final PublishTriggerChannelConfig config;
28 private final ChannelUID uid;
29 private final XMPPClientHandler handler;
31 PublishTriggerChannel(PublishTriggerChannelConfig config, ChannelUID uid, XMPPClient connection,
32 XMPPClientHandler handler) {
35 this.connection = connection;
36 this.handler = handler;
40 connection.subscribe(this);
44 connection.unsubscribe(this);
48 public void processMessage(String from, String payload) {
49 // Check condition if exists
50 String expectedPayload = config.payload;
51 if ((expectedPayload != null) && (!expectedPayload.isEmpty()) && !payload.equals(expectedPayload)) {
54 String eventValue = "";
55 if (!config.separator.isEmpty()) {
56 eventValue = from + config.separator + payload;
60 handler.triggerChannel(uid, eventValue);
64 public String getName() {
65 return uid.toString();