From cce185af647974a51b3a854a1272196e70391364 Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Thu, 29 May 2025 10:02:00 +0200 Subject: [PATCH] UPNP don't notify embedded child devices by default (#4735) Signed-off-by: Andrew Fiddian-Green --- .../discovery/upnp/UpnpDiscoveryParticipant.java | 10 ++++++++++ .../discovery/upnp/internal/UpnpDiscoveryService.java | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/UpnpDiscoveryParticipant.java b/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/UpnpDiscoveryParticipant.java index 8050b82f0f..5ffba2f142 100644 --- a/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/UpnpDiscoveryParticipant.java +++ b/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/UpnpDiscoveryParticipant.java @@ -79,4 +79,14 @@ public interface UpnpDiscoveryParticipant { default long getRemovalGracePeriodSeconds(RemoteDevice device) { return 0; } + + /** + * The discovery always notifies participants about discovered root devices. And if the participant also + * wants to be notified about embedded child devices then it shall override this method. + * + * @return true if the participant wants to be also notified about embedded child devices. + */ + default boolean notifyChildDevices() { + return false; + } } diff --git a/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/internal/UpnpDiscoveryService.java b/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/internal/UpnpDiscoveryService.java index a355c2e862..893297d0f9 100644 --- a/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/internal/UpnpDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery.upnp/src/main/java/org/openhab/core/config/discovery/upnp/internal/UpnpDiscoveryService.java @@ -113,6 +113,9 @@ public class UpnpDiscoveryService extends AbstractDiscoveryService Collection devices = upnpService.getRegistry().getRemoteDevices(); for (RemoteDevice device : devices) { + if (!device.isRoot() && !participant.notifyChildDevices()) { + continue; + } DiscoveryResult result = participant.createResult(device); if (result != null) { final DiscoveryResult resultNew = getLocalizedDiscoveryResult(result, @@ -171,6 +174,9 @@ public class UpnpDiscoveryService extends AbstractDiscoveryService @Override public void remoteDeviceAdded(Registry registry, RemoteDevice device) { for (UpnpDiscoveryParticipant participant : participants) { + if (!device.isRoot() && !participant.notifyChildDevices()) { + continue; + } try { DiscoveryResult result = participant.createResult(device); if (result != null) { @@ -200,6 +206,9 @@ public class UpnpDiscoveryService extends AbstractDiscoveryService @Override public void remoteDeviceRemoved(Registry registry, RemoteDevice device) { for (UpnpDiscoveryParticipant participant : participants) { + if (!device.isRoot() && !participant.notifyChildDevices()) { + continue; + } try { ThingUID thingUID = participant.getThingUID(device); if (thingUID != null) {