[mqtt.homeassistant] support availability_templates (#13397)
Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
@@ -291,12 +291,13 @@ public abstract class AbstractMQTTThingHandler extends BaseThingHandler
|
||||
addAvailabilityTopic(availability_topic, payload_available, payload_not_available, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available,
|
||||
@Nullable String transformation_pattern,
|
||||
@Nullable TransformationServiceProvider transformationServiceProvider) {
|
||||
availabilityStates.computeIfAbsent(availability_topic, topic -> {
|
||||
Value value = new OnOffValue(payload_available, payload_not_available);
|
||||
ChannelGroupUID groupUID = new ChannelGroupUID(getThing().getUID(), "availablility");
|
||||
ChannelGroupUID groupUID = new ChannelGroupUID(getThing().getUID(), "availability");
|
||||
ChannelUID channelUID = new ChannelUID(groupUID, UIDUtils.encode(topic));
|
||||
ChannelState state = new ChannelState(ChannelConfigBuilder.create().withStateTopic(topic).build(),
|
||||
channelUID, value, new ChannelStateUpdateListener() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.mqtt.generic;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Interface to keep track of the availability of device using an availability topic or messages received
|
||||
@@ -33,6 +34,23 @@ public interface AvailabilityTracker {
|
||||
*/
|
||||
public void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available);
|
||||
|
||||
/**
|
||||
* Adds an availability topic to determine the availability of a device.
|
||||
* <p>
|
||||
* Availability topics are usually set by the device as LWT.
|
||||
*
|
||||
* @param availability_topic The MQTT topic where availability is published to.
|
||||
* @param payload_available The value for the topic to indicate the device is online.
|
||||
* @param payload_not_available The value for the topic to indicate the device is offline.
|
||||
* @param transformation_pattern A transformation pattern to process the value before comparing to
|
||||
* payload_available/payload_not_available.
|
||||
* @param transformationServiceProvider The service provider to obtain the transformation service (required only if
|
||||
* transformation_pattern is not null).
|
||||
*/
|
||||
public void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available,
|
||||
@Nullable String transformation_pattern,
|
||||
@Nullable TransformationServiceProvider transformationServiceProvider);
|
||||
|
||||
public void removeAvailabilityTopic(String availability_topic);
|
||||
|
||||
public void clearAllAvailabilityTopics();
|
||||
|
||||
Reference in New Issue
Block a user