[chromecast] Fix constant disconnections (#14105)

When ipv6 is configured on the network, Chromecast devices will randomly
return ipv4 and/or multiple ipv6 addresses during mdns discovery.
This would trigger a thingUpdated call which will call dispose/initialize,
causing the thing to go offline/online.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2022-12-29 20:52:25 +10:00 committed by GitHub
parent 3bf6f5219b
commit f87ff2f9ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ package org.openhab.binding.chromecast.internal.discovery;
import static org.openhab.binding.chromecast.internal.ChromecastBindingConstants.*; import static org.openhab.binding.chromecast.internal.ChromecastBindingConstants.*;
import java.net.Inet4Address;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -89,7 +90,11 @@ public class ChromecastDiscoveryParticipant implements MDNSDiscoveryParticipant
if (isAutoDiscoveryEnabled) { if (isAutoDiscoveryEnabled) {
ThingUID uid = getThingUID(service); ThingUID uid = getThingUID(service);
if (uid != null) { if (uid != null) {
String host = service.getHostAddresses()[0]; Inet4Address[] addresses = service.getInet4Addresses();
if (addresses.length == 0) {
return null;
}
String host = addresses[0].getHostAddress();
int port = service.getPort(); int port = service.getPort();
logger.debug("Chromecast Found: {} {}", host, port); logger.debug("Chromecast Found: {} {}", host, port);
String id = service.getPropertyString(PROPERTY_DEVICE_ID); String id = service.getPropertyString(PROPERTY_DEVICE_ID);