Skip to content

Commit

Permalink
[wemo] Do http (not port) ping to determine if wemo port is alive (op…
Browse files Browse the repository at this point in the history
…enhab#7874)

* Poll using http not icmp
* remove throw

Signed-off-by: bill <[email protected]>
  • Loading branch information
billfor authored and andrewfg committed Aug 31, 2020
1 parent 4c03e0b commit bcd86b9
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bcd86b9

Please sign in to comment.