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 {@link AbstractBrokerHandler#triggerChannel(ChannelUID, String)} if a value has been
22 * @author Pavel Gololobov - Initial contribution
24 public class PublishTriggerChannel implements XMPPClientMessageSubscriber {
25 private final XMPPClient connection;
26 private final PublishTriggerChannelConfig config;
27 private final ChannelUID uid;
28 private final XMPPClientHandler handler;
30 PublishTriggerChannel(PublishTriggerChannelConfig config, ChannelUID uid, XMPPClient connection,
31 XMPPClientHandler handler) {
34 this.connection = connection;
35 this.handler = handler;
39 connection.subscribe(this);
43 connection.unsubscribe(this);
47 public void processMessage(String from, String payload) {
48 // Check condition if exists
49 String expectedPayload = config.payload;
50 if ((expectedPayload != null) && (!expectedPayload.isEmpty()) && !payload.equals(expectedPayload)) {
53 String eventValue = "";
54 if (!config.separator.isEmpty()) {
55 eventValue = from + config.separator + payload;
59 handler.triggerChannel(uid, eventValue);
63 public String getName() {
64 return uid.toString();