From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Thu, 29 Dec 2022 10:52:25 +0000 (+1000) Subject: [chromecast] Fix constant disconnections (#14105) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=f87ff2f9cef16a7110403e23174bc2333950efba;p=openhab-addons.git [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 --- diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/discovery/ChromecastDiscoveryParticipant.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/discovery/ChromecastDiscoveryParticipant.java index 1aad236ae4..682042cfaa 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/discovery/ChromecastDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/discovery/ChromecastDiscoveryParticipant.java @@ -14,6 +14,7 @@ package org.openhab.binding.chromecast.internal.discovery; import static org.openhab.binding.chromecast.internal.ChromecastBindingConstants.*; +import java.net.Inet4Address; import java.util.Dictionary; import java.util.Map; import java.util.Set; @@ -89,7 +90,11 @@ public class ChromecastDiscoveryParticipant implements MDNSDiscoveryParticipant if (isAutoDiscoveryEnabled) { ThingUID uid = getThingUID(service); 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(); logger.debug("Chromecast Found: {} {}", host, port); String id = service.getPropertyString(PROPERTY_DEVICE_ID);