Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mqtt][homie] Delete '$name' subscription in discovery service #8017

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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