Skip to content

Commit

Permalink
[mqtt][homie] Delete '$name' subscription in discovery service (openh…
Browse files Browse the repository at this point in the history
…ab#8017)

Closes openhab#7252

Signed-off-by: Aitor Iturrioz <riturrioz@gmail.com>
  • Loading branch information
bodiroga authored and CSchlipp committed Sep 12, 2020
1 parent 614272f commit 932bb2e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> delayedProcessing;
private @Nullable ScheduledFuture<?> heartBeatTimer;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 932bb2e

Please sign in to comment.