Search in sources :

Example 1 with TopicSubscribe

use of org.eclipse.smarthome.binding.mqtt.discovery.TopicSubscribe in project smarthome by eclipse.

the class TopicSubscribeMultiConnection method add.

/**
 * Add thing if it is a bridge and has a handler that inherits from {@link AbstractBrokerHandler}.
 */
public void add(AbstractBrokerHandler handler) {
    final ThingUID bridgeUid = handler.getThing().getUID();
    handler.getConnectionAsync().thenAccept(connection -> {
        final TopicSubscribe o = new TopicSubscribe(connection, topic, messageReceivedListener, bridgeUid);
        observedBrokerHandlers.put(bridgeUid, o);
        o.start().exceptionally(e -> {
            logger.warn("Failed to MQTT subscribe for {} on topic {}", bridgeUid, topic);
            return false;
        }).thenRun(() -> {
            logger.trace("Found suitable bridge {} for listing to topic {}", bridgeUid, topic);
        });
    });
}
Also used : AbstractBrokerHandler(org.eclipse.smarthome.binding.mqtt.handler.AbstractBrokerHandler) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) Map(java.util.Map) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MQTTTopicDiscoveryParticipant(org.eclipse.smarthome.binding.mqtt.discovery.MQTTTopicDiscoveryParticipant) TopicSubscribe(org.eclipse.smarthome.binding.mqtt.discovery.TopicSubscribe) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) TopicSubscribe(org.eclipse.smarthome.binding.mqtt.discovery.TopicSubscribe)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 MQTTTopicDiscoveryParticipant (org.eclipse.smarthome.binding.mqtt.discovery.MQTTTopicDiscoveryParticipant)1 TopicSubscribe (org.eclipse.smarthome.binding.mqtt.discovery.TopicSubscribe)1 AbstractBrokerHandler (org.eclipse.smarthome.binding.mqtt.handler.AbstractBrokerHandler)1 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1