2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ipobserver.internal;
15 import static org.openhab.binding.ipobserver.internal.IpObserverBindingConstants.LIVE_DATA_URL;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.TimeUnit;
19 import java.util.concurrent.TimeoutException;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jetty.client.api.ContentResponse;
23 import org.eclipse.jetty.client.api.Request;
24 import org.eclipse.jetty.http.HttpHeader;
25 import org.eclipse.jetty.http.HttpMethod;
28 * The {@link IpObserverDiscoveryJob} class allows auto discovery of
29 * devices for a single IP address. This is used
30 * for threading to make discovery faster.
32 * @author Matthew Skinner - Initial contribution
35 public class IpObserverDiscoveryJob implements Runnable {
36 private IpObserverDiscoveryService discoveryClass;
37 private String ipAddress;
39 public IpObserverDiscoveryJob(IpObserverDiscoveryService service, String ip) {
40 this.discoveryClass = service;
46 if (isIpObserverDevice(this.ipAddress)) {
47 discoveryClass.submitDiscoveryResults(this.ipAddress);
51 private boolean isIpObserverDevice(String ip) {
52 Request request = discoveryClass.getHttpClient().newRequest("http://" + ip + LIVE_DATA_URL);
53 request.method(HttpMethod.GET).timeout(5, TimeUnit.SECONDS).header(HttpHeader.ACCEPT_ENCODING, "gzip");
54 ContentResponse contentResponse;
56 contentResponse = request.send();
57 if (contentResponse.getStatus() == 200 && contentResponse.getContentAsString().contains("livedata.htm")) {
60 } catch (InterruptedException | TimeoutException | ExecutionException e) {