From 03d9281c0b4634e5844fc28f907110a2be154e44 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Tue, 13 Jul 2021 12:29:54 +0200 Subject: [PATCH] [sonos] Filter Sonos Sub from discovery (#10925) Fix #10777 Signed-off-by: Laurent Garnier --- .../ZonePlayerDiscoveryParticipant.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java index f9102a9e67bff..8b84df74bd513 100644 --- a/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/internal/discovery/ZonePlayerDiscoveryParticipant.java @@ -80,6 +80,7 @@ public Set getSupportedThingTypeUIDs() { public @Nullable ThingUID getThingUID(RemoteDevice device) { if (device.getDetails().getManufacturerDetails().getManufacturer() != null) { if (device.getDetails().getManufacturerDetails().getManufacturer().toUpperCase().contains("SONOS")) { + boolean ignored = false; String modelName = getModelName(device); switch (modelName) { case "ZP80": @@ -94,22 +95,28 @@ public Set getSupportedThingTypeUIDs() { case "Arc SL": modelName = "ArcSL"; break; + case "Sub": + // The Sonos Sub is ignored + ignored = true; + break; default: break; } - ThingTypeUID thingUID = new ThingTypeUID(SonosBindingConstants.BINDING_ID, modelName); - if (!SonosBindingConstants.SUPPORTED_KNOWN_THING_TYPES_UIDS.contains(thingUID)) { - // Try with the model name all in uppercase - thingUID = new ThingTypeUID(SonosBindingConstants.BINDING_ID, modelName.toUpperCase()); - // In case a new "unknown" Sonos player is discovered a generic ThingTypeUID will be used + if (!ignored) { + ThingTypeUID thingUID = new ThingTypeUID(SonosBindingConstants.BINDING_ID, modelName); if (!SonosBindingConstants.SUPPORTED_KNOWN_THING_TYPES_UIDS.contains(thingUID)) { - thingUID = SonosBindingConstants.ZONEPLAYER_THING_TYPE_UID; + // Try with the model name all in uppercase + thingUID = new ThingTypeUID(SonosBindingConstants.BINDING_ID, modelName.toUpperCase()); + // In case a new "unknown" Sonos player is discovered a generic ThingTypeUID will be used + if (!SonosBindingConstants.SUPPORTED_KNOWN_THING_TYPES_UIDS.contains(thingUID)) { + thingUID = SonosBindingConstants.ZONEPLAYER_THING_TYPE_UID; + } } - } - logger.debug("Discovered a Sonos '{}' thing with UDN '{}'", thingUID, - device.getIdentity().getUdn().getIdentifierString()); - return new ThingUID(thingUID, device.getIdentity().getUdn().getIdentifierString()); + logger.debug("Discovered a Sonos '{}' thing with UDN '{}'", thingUID, + device.getIdentity().getUdn().getIdentifierString()); + return new ThingUID(thingUID, device.getIdentity().getUdn().getIdentifierString()); + } } }