2 * Copyright (c) 2010-2024 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.mqtt.generic;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * Interface to keep track of the availability of device using an availability topic or messages received
21 * @author Jochen Klein - Initial contribution
22 * @author Cody Cutrer - Support all/any/latest
25 public interface AvailabilityTracker {
27 * controls the conditions needed to set the entity to available
29 enum AvailabilityMode {
31 * payload_available must be received on all configured availability topics before the entity is marked as
37 * payload_available must be received on at least one configured availability topic before the entity is marked
43 * the last payload_available or payload_not_available received on any configured availability topic controls
50 * Sets how multiple availability topics are treated
52 void setAvailabilityMode(AvailabilityMode mode);
55 * Adds an availability topic to determine the availability of a device.
57 * Availability topics are usually set by the device as LWT.
59 * @param availability_topic
60 * @param payload_available
61 * @param payload_not_available
63 void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available);
66 * Adds an availability topic to determine the availability of a device.
68 * Availability topics are usually set by the device as LWT.
70 * @param availability_topic The MQTT topic where availability is published to.
71 * @param payload_available The value for the topic to indicate the device is online.
72 * @param payload_not_available The value for the topic to indicate the device is offline.
73 * @param transformation_pattern A transformation pattern to process the value before comparing to
74 * payload_available/payload_not_available.
75 * @param transformationServiceProvider The service provider to obtain the transformation service (required only if
76 * transformation_pattern is not null).
78 void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available,
79 @Nullable String transformation_pattern,
80 @Nullable TransformationServiceProvider transformationServiceProvider);
82 void removeAvailabilityTopic(String availability_topic);
84 void clearAllAvailabilityTopics();
87 * resets the indicator, if messages have been received.
89 * This is used to time out the availability of the device after some time without receiving a message.
91 void resetMessageReceived();