mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[pjlinkdevice] Remove org.apache.common (#14430)
* Remove org.apache.common Signed-off-by: Leo Siepel <leosiepel@gmail.com> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
4dd40b48c0
commit
98661fde91
@ -13,11 +13,7 @@
|
||||
package org.openhab.binding.pjlinkdevice.internal.discovery;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -27,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.pjlinkdevice.internal.PJLinkDeviceBindingConstants;
|
||||
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
||||
import org.openhab.core.net.NetUtil;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.slf4j.Logger;
|
||||
@ -63,7 +60,7 @@ public abstract class AbstractDiscoveryParticipant extends AbstractDiscoveryServ
|
||||
@Override
|
||||
protected void startScan() {
|
||||
logger.trace("PJLinkProjectorDiscoveryParticipant startScan");
|
||||
Set<InetAddress> addressesToScan = generateAddressesToScan();
|
||||
List<InetAddress> addressesToScan = NetUtil.getFullRangeOfAddressesToScan();
|
||||
scannedIPcount = 0;
|
||||
for (InetAddress ip : addressesToScan) {
|
||||
getExecutorService().execute(() -> {
|
||||
@ -106,26 +103,4 @@ public abstract class AbstractDiscoveryParticipant extends AbstractDiscoveryServ
|
||||
}
|
||||
|
||||
protected abstract void checkAddress(InetAddress ip, int tcpPort, int timeout);
|
||||
|
||||
private Set<InetAddress> generateAddressesToScan() {
|
||||
try {
|
||||
Set<InetAddress> addressesToScan = new HashSet<>();
|
||||
ArrayList<NetworkInterface> interfaces = java.util.Collections
|
||||
.list(NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface networkInterface : interfaces) {
|
||||
if (networkInterface.isLoopback() || !networkInterface.isUp()) {
|
||||
continue;
|
||||
}
|
||||
for (InterfaceAddress i : networkInterface.getInterfaceAddresses()) {
|
||||
collectAddressesToScan(addressesToScan, i);
|
||||
}
|
||||
}
|
||||
return addressesToScan;
|
||||
} catch (SocketException e) {
|
||||
logger.debug("Could not enumerate network interfaces", e);
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
protected abstract void collectAddressesToScan(Set<InetAddress> addressesToScan, InterfaceAddress i);
|
||||
}
|
||||
|
@ -13,15 +13,11 @@
|
||||
package org.openhab.binding.pjlinkdevice.internal.discovery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.pjlinkdevice.internal.PJLinkDeviceBindingConstants;
|
||||
import org.openhab.binding.pjlinkdevice.internal.device.PJLinkDevice;
|
||||
@ -41,33 +37,11 @@ import org.osgi.service.component.annotations.Component;
|
||||
@NonNullByDefault
|
||||
public class DiscoveryParticipantClass1 extends AbstractDiscoveryParticipant {
|
||||
public DiscoveryParticipantClass1() throws IllegalArgumentException {
|
||||
super(Set.of(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true);
|
||||
super(Collections.singleton(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true);
|
||||
|
||||
logger.trace("PJLinkProjectorDiscoveryParticipant constructor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectAddressesToScan(Set<InetAddress> addressesToScan, InterfaceAddress i) {
|
||||
// only scan IPv4
|
||||
if (!(i.getAddress() instanceof Inet4Address)) {
|
||||
return;
|
||||
}
|
||||
// only scan Class C networks
|
||||
if (i.getNetworkPrefixLength() < 24) {
|
||||
return;
|
||||
}
|
||||
|
||||
SubnetUtils utils = new SubnetUtils(i.getAddress().getHostAddress() + "/" + i.getNetworkPrefixLength());
|
||||
for (String addressToScan : utils.getInfo().getAllAddresses()) {
|
||||
try {
|
||||
logger.debug("Add address to scan: {}", addressToScan);
|
||||
addressesToScan.add(InetAddress.getByName(addressToScan));
|
||||
} catch (UnknownHostException e) {
|
||||
logger.debug("Unknown Host", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkAddress(InetAddress ip, int tcpPort, int timeout) {
|
||||
PJLinkDevice device = new PJLinkDevice(tcpPort, ip, null, timeout);
|
||||
|
Loading…
Reference in New Issue
Block a user