diff --git a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttBindingConstants.java b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttBindingConstants.java index fb18a55edd2e9..1a7aec6d6e870 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttBindingConstants.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttBindingConstants.java @@ -33,4 +33,8 @@ public class MqttBindingConstants { public static final String HOMIE_PROPERTY_VERSION = "homieversion"; public static final String HOMIE_PROPERTY_HEARTBEAT_INTERVAL = "heartbeat_interval"; + + public static final int HOMIE_DEVICE_TIMEOUT_MS = 15000; + public static final int HOMIE_SUBSCRIBE_TIMEOUT_MS = 500; + public static final int HOMIE_ATTRIBUTE_TIMEOUT_MS = 200; } diff --git a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttThingHandlerFactory.java b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttThingHandlerFactory.java index 45df573aed3fd..5e529d5ac2bf6 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttThingHandlerFactory.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttThingHandlerFactory.java @@ -89,7 +89,8 @@ protected void unsetChannelProvider(MqttChannelTypeProvider provider) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(MqttBindingConstants.HOMIE300_MQTT_THING)) { - return new HomieThingHandler(thing, typeProvider, 1000, 500); + return new HomieThingHandler(thing, typeProvider, MqttBindingConstants.HOMIE_DEVICE_TIMEOUT_MS, + MqttBindingConstants.HOMIE_SUBSCRIBE_TIMEOUT_MS, MqttBindingConstants.HOMIE_ATTRIBUTE_TIMEOUT_MS); } return null; } diff --git a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/discovery/Homie300Discovery.java b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/discovery/Homie300Discovery.java index 936025a44ce74..da6e4aee668a9 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/discovery/Homie300Discovery.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/discovery/Homie300Discovery.java @@ -25,7 +25,6 @@ import org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection; import org.openhab.binding.mqtt.discovery.AbstractMQTTDiscovery; import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryService; -import org.openhab.binding.mqtt.generic.tools.WaitForTopicValue; import org.openhab.binding.mqtt.homie.generic.internal.MqttBindingConstants; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -92,12 +91,7 @@ public void receivedMessage(ThingUID connectionBridge, MqttBrokerConnection conn return; } - // Retrieve name and update found discovery - WaitForTopicValue w = new WaitForTopicValue(connection, topic.replace("$homie", "$name")); - w.waitForTopicValueAsync(scheduler, 700).whenComplete((name, ex) -> { - String deviceName = ex == null ? name : deviceID; - publishDevice(connectionBridge, connection, deviceID, topic, deviceName); - }); + publishDevice(connectionBridge, connection, deviceID, topic, deviceID); } void publishDevice(ThingUID connectionBridge, MqttBrokerConnection connection, String deviceID, String topic, diff --git a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandler.java b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandler.java index 5dfe6a9ad7e9f..2c6002be378d7 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandler.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandler.java @@ -55,6 +55,7 @@ public class HomieThingHandler extends AbstractMQTTThingHandler implements Devic /** The timeout per attribute field subscription */ protected final int attributeReceiveTimeout; protected final int subscribeTimeout; + protected final int deviceTimeout; protected HandlerConfiguration config = new HandlerConfiguration(); protected DelayedBatchProcessing delayedProcessing; private @Nullable ScheduledFuture heartBeatTimer; @@ -65,15 +66,17 @@ public class HomieThingHandler extends AbstractMQTTThingHandler implements Devic * * @param thing The thing of this handler * @param channelTypeProvider A channel type provider + * @param deviceTimeout Timeout for the entire device subscription. In milliseconds. * @param subscribeTimeout Timeout for an entire attribute class subscription and receive. In milliseconds. * Even a slow remote device will publish a full node or property within 100ms. * @param attributeReceiveTimeout The timeout per attribute field subscription. In milliseconds. * One attribute subscription and receiving should not take longer than 50ms. */ - public HomieThingHandler(Thing thing, MqttChannelTypeProvider channelTypeProvider, int subscribeTimeout, - int attributeReceiveTimeout) { - super(thing, subscribeTimeout); + public HomieThingHandler(Thing thing, MqttChannelTypeProvider channelTypeProvider, int deviceTimeout, + int subscribeTimeout, int attributeReceiveTimeout) { + super(thing, deviceTimeout); this.channelTypeProvider = channelTypeProvider; + this.deviceTimeout = deviceTimeout; this.subscribeTimeout = subscribeTimeout; this.attributeReceiveTimeout = attributeReceiveTimeout; this.delayedProcessing = new DelayedBatchProcessing<>(subscribeTimeout, this, scheduler); diff --git a/bundles/org.openhab.binding.mqtt.homie/src/test/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandlerTests.java b/bundles/org.openhab.binding.mqtt.homie/src/test/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandlerTests.java index ce61a0a7ff5c9..f0e03660998dc 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/test/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandlerTests.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/test/java/org/openhab/binding/mqtt/homie/internal/handler/HomieThingHandlerTests.java @@ -132,7 +132,7 @@ public void setUp() { doReturn(false).when(scheduledFuture).isDone(); doReturn(scheduledFuture).when(scheduler).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class)); - final HomieThingHandler handler = new HomieThingHandler(thing, channelTypeProvider, 30, 5); + final HomieThingHandler handler = new HomieThingHandler(thing, channelTypeProvider, 1000, 30, 5); thingHandler = spy(handler); thingHandler.setCallback(callback); final Device device = new Device(thing.getUID(), thingHandler, spy(new DeviceAttributes()),