From bcd86b9ac2d9a727c045f9f7d9fa9fcb1c59e857 Mon Sep 17 00:00:00 2001 From: billfor Date: Tue, 9 Jun 2020 11:54:49 -0400 Subject: [PATCH] [wemo] Do http (not port) ping to determine if wemo port is alive (#7874) * Poll using http not icmp * remove throw Signed-off-by: bill --- .../wemo/internal/handler/WemoHandler.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java index 1e094266d263d..25efd72b1a745 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java @@ -17,12 +17,6 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.net.ConnectException; -import java.net.InetSocketAddress; -import java.net.NoRouteToHostException; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.SocketTimeoutException; import java.net.URL; import java.time.Instant; import java.time.ZonedDateTime; @@ -49,6 +43,7 @@ import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.RefreshType; import org.eclipse.smarthome.core.types.State; +import org.eclipse.smarthome.io.net.http.HttpUtil; import org.eclipse.smarthome.io.transport.upnp.UpnpIOParticipant; import org.eclipse.smarthome.io.transport.upnp.UpnpIOService; import org.openhab.binding.wemo.internal.http.WemoHttpCall; @@ -480,20 +475,20 @@ public String getWemoURL(String actionService) { } } wemoURL = "http://" + host + ":" + port + "/upnp/control/" + actionService + "1"; + logger.trace("WeMo url {}", wemoURL); return wemoURL; } return wemoURL; } - public boolean servicePing(String host, int port) throws IOException { - SocketAddress socketAddress = new InetSocketAddress(host, port); - try (Socket socket = new Socket()) { - logger.trace("Ping WeMo device at '{}'", socketAddress); - socket.connect(socketAddress, 250); - return true; - } catch (ConnectException | SocketTimeoutException | NoRouteToHostException ignored) { + public boolean servicePing(String host, int port) { + logger.trace("Ping WeMo device at '{}:{}'", host, port); + try { + HttpUtil.executeUrl("GET", "http://" + host + ":" + port, 250); + } catch (IOException e) { return false; } + return true; } @Override