[bluetooth] Null annotations and SAT (#13967)
* null annotation, checkstyle, dependency Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
ca09f71a6c
commit
539f49e4ec
|
@ -12,11 +12,15 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth;
|
package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothAddress} class defines a bluetooth address
|
* The {@link BluetoothAddress} class defines a bluetooth address
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothAddress {
|
public class BluetoothAddress {
|
||||||
|
|
||||||
public static final int BD_ADDRESS_LENGTH = 17;
|
public static final int BD_ADDRESS_LENGTH = 17;
|
||||||
|
@ -28,7 +32,7 @@ public class BluetoothAddress {
|
||||||
*
|
*
|
||||||
* @param address the device address
|
* @param address the device address
|
||||||
*/
|
*/
|
||||||
public BluetoothAddress(String address) {
|
public BluetoothAddress(@Nullable String address) {
|
||||||
if (address == null || address.length() != BD_ADDRESS_LENGTH) {
|
if (address == null || address.length() != BD_ADDRESS_LENGTH) {
|
||||||
throw new IllegalArgumentException("BT Address cannot be null and must be in format XX:XX:XX:XX:XX:XX");
|
throw new IllegalArgumentException("BT Address cannot be null and must be in format XX:XX:XX:XX:XX:XX");
|
||||||
}
|
}
|
||||||
|
@ -58,12 +62,12 @@ public class BluetoothAddress {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
result = prime * result + address.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -74,14 +78,8 @@ public class BluetoothAddress {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BluetoothAddress other = (BluetoothAddress) obj;
|
BluetoothAddress other = (BluetoothAddress) obj;
|
||||||
if (address == null) {
|
|
||||||
if (other.address != null) {
|
return address.equals(other.address);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!address.equals(other.address)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,8 +18,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothCharacteristic} class defines the Bluetooth characteristic.
|
* The {@link BluetoothCharacteristic} class defines the Bluetooth characteristic.
|
||||||
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Kai Kreuzer - Cleaned up code
|
* @author Kai Kreuzer - Cleaned up code
|
||||||
* @author Peter Rosenberg - Improve properties support
|
* @author Peter Rosenberg - Improve properties support
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothCharacteristic {
|
public class BluetoothCharacteristic {
|
||||||
public static final int PROPERTY_BROADCAST = 0x01;
|
public static final int PROPERTY_BROADCAST = 0x01;
|
||||||
public static final int PROPERTY_READ = 0x02;
|
public static final int PROPERTY_READ = 0x02;
|
||||||
|
@ -55,8 +56,6 @@ public class BluetoothCharacteristic {
|
||||||
public static final int WRITE_TYPE_NO_RESPONSE = 0x01;
|
public static final int WRITE_TYPE_NO_RESPONSE = 0x01;
|
||||||
public static final int WRITE_TYPE_SIGNED = 0x04;
|
public static final int WRITE_TYPE_SIGNED = 0x04;
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(BluetoothCharacteristic.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link UUID} for this characteristic
|
* The {@link UUID} for this characteristic
|
||||||
*/
|
*/
|
||||||
|
@ -79,7 +78,7 @@ public class BluetoothCharacteristic {
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothService} to which this characteristic belongs
|
* The {@link BluetoothService} to which this characteristic belongs
|
||||||
*/
|
*/
|
||||||
protected BluetoothService service;
|
protected @Nullable BluetoothService service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new BluetoothCharacteristic.
|
* Create a new BluetoothCharacteristic.
|
||||||
|
@ -217,7 +216,7 @@ public class BluetoothCharacteristic {
|
||||||
*
|
*
|
||||||
* @return the {@link BluetoothService}
|
* @return the {@link BluetoothService}
|
||||||
*/
|
*/
|
||||||
public BluetoothService getService() {
|
public @Nullable BluetoothService getService() {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,22 +252,23 @@ public class BluetoothCharacteristic {
|
||||||
*
|
*
|
||||||
* @return the {@link BluetoothDescriptor}
|
* @return the {@link BluetoothDescriptor}
|
||||||
*/
|
*/
|
||||||
public BluetoothDescriptor getDescriptor(UUID uuid) {
|
public @Nullable BluetoothDescriptor getDescriptor(UUID uuid) {
|
||||||
return gattDescriptors.get(uuid);
|
return gattDescriptors.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
BluetoothService btService = service;
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + instance;
|
result = prime * result + instance;
|
||||||
result = prime * result + ((service == null) ? 0 : service.hashCode());
|
result = prime * result + ((btService == null) ? 0 : btService.hashCode());
|
||||||
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
result = prime * result + uuid.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -282,24 +282,19 @@ public class BluetoothCharacteristic {
|
||||||
if (instance != other.instance) {
|
if (instance != other.instance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (service == null) {
|
BluetoothService btService = service;
|
||||||
|
if (btService == null) {
|
||||||
if (other.service != null) {
|
if (other.service != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!service.equals(other.service)) {
|
} else if (!btService.equals(other.service)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (uuid == null) {
|
|
||||||
if (other.uuid != null) {
|
return uuid.equals(other.uuid);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!uuid.equals(other.uuid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GattCharacteristic getGattCharacteristic() {
|
public @Nullable GattCharacteristic getGattCharacteristic() {
|
||||||
return GattCharacteristic.getCharacteristic(uuid);
|
return GattCharacteristic.getCharacteristic(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +405,7 @@ public class BluetoothCharacteristic {
|
||||||
REMOVABLE(0x2A3A),
|
REMOVABLE(0x2A3A),
|
||||||
SERVICE_REQUIRED(0x2A3B);
|
SERVICE_REQUIRED(0x2A3B);
|
||||||
|
|
||||||
private static Map<UUID, GattCharacteristic> uuidToServiceMapping;
|
private static @Nullable Map<UUID, GattCharacteristic> uuidToServiceMapping;
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
|
@ -418,18 +413,16 @@ public class BluetoothCharacteristic {
|
||||||
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initMapping() {
|
public static @Nullable GattCharacteristic getCharacteristic(UUID uuid) {
|
||||||
uuidToServiceMapping = new HashMap<>();
|
Map<UUID, GattCharacteristic> localServiceMapping = uuidToServiceMapping;
|
||||||
for (GattCharacteristic s : values()) {
|
if (localServiceMapping == null) {
|
||||||
uuidToServiceMapping.put(s.uuid, s);
|
localServiceMapping = new HashMap<>();
|
||||||
|
for (GattCharacteristic s : values()) {
|
||||||
|
localServiceMapping.put(s.uuid, s);
|
||||||
|
}
|
||||||
|
uuidToServiceMapping = localServiceMapping;
|
||||||
}
|
}
|
||||||
}
|
return localServiceMapping.get(uuid);
|
||||||
|
|
||||||
public static GattCharacteristic getCharacteristic(UUID uuid) {
|
|
||||||
if (uuidToServiceMapping == null) {
|
|
||||||
initMapping();
|
|
||||||
}
|
|
||||||
return uuidToServiceMapping.get(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,12 +12,15 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth;
|
package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Bluetooth class, which describes the general characteristics and capabilities of a device.
|
* Represents a Bluetooth class, which describes the general characteristics and capabilities of a device.
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial Contribution
|
* @author Chris Jackson - Initial Contribution
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothClass {
|
public class BluetoothClass {
|
||||||
private final int clazz;
|
private final int clazz;
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,15 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth;
|
package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enumeration of transaction completion status values
|
* An enumeration of transaction completion status values
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public enum BluetoothCompletionStatus {
|
public enum BluetoothCompletionStatus {
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
ERROR
|
ERROR
|
||||||
|
|
|
@ -16,6 +16,9 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothDescriptor} class defines the Bluetooth descriptor.
|
* The {@link BluetoothDescriptor} class defines the Bluetooth descriptor.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -26,6 +29,7 @@ import java.util.UUID;
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
* @author Kai Kreuzer - added constructor and fixed setValue method
|
* @author Kai Kreuzer - added constructor and fixed setValue method
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothDescriptor {
|
public class BluetoothDescriptor {
|
||||||
|
|
||||||
protected final BluetoothCharacteristic characteristic;
|
protected final BluetoothCharacteristic characteristic;
|
||||||
|
@ -81,7 +85,7 @@ public class BluetoothDescriptor {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GattDescriptor getDescriptor() {
|
public @Nullable GattDescriptor getDescriptor() {
|
||||||
return GattDescriptor.getDescriptor(uuid);
|
return GattDescriptor.getDescriptor(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +103,7 @@ public class BluetoothDescriptor {
|
||||||
NUMBER_OF_DIGITALS(0x2909),
|
NUMBER_OF_DIGITALS(0x2909),
|
||||||
TRIGGER_SETTING(0x290A);
|
TRIGGER_SETTING(0x290A);
|
||||||
|
|
||||||
private static Map<UUID, GattDescriptor> uuidToServiceMapping;
|
private static @Nullable Map<UUID, GattDescriptor> uuidToServiceMapping;
|
||||||
|
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
|
@ -107,18 +111,16 @@ public class BluetoothDescriptor {
|
||||||
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initMapping() {
|
public static @Nullable GattDescriptor getDescriptor(UUID uuid) {
|
||||||
uuidToServiceMapping = new HashMap<>();
|
Map<UUID, GattDescriptor> localServiceMapping = uuidToServiceMapping;
|
||||||
for (GattDescriptor s : values()) {
|
if (localServiceMapping == null) {
|
||||||
uuidToServiceMapping.put(s.uuid, s);
|
localServiceMapping = new HashMap<>();
|
||||||
|
for (GattDescriptor s : values()) {
|
||||||
|
localServiceMapping.put(s.uuid, s);
|
||||||
|
}
|
||||||
|
uuidToServiceMapping = localServiceMapping;
|
||||||
}
|
}
|
||||||
}
|
return localServiceMapping.get(uuid);
|
||||||
|
|
||||||
public static GattDescriptor getDescriptor(UUID uuid) {
|
|
||||||
if (uuidToServiceMapping == null) {
|
|
||||||
initMapping();
|
|
||||||
}
|
|
||||||
return uuidToServiceMapping.get(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,6 +19,9 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothCharacteristic} class defines the BLE Service.
|
* The {@link BluetoothCharacteristic} class defines the BLE Service.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -30,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
* @author Kai Kreuzer - Cleaned up code
|
* @author Kai Kreuzer - Cleaned up code
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothService {
|
public class BluetoothService {
|
||||||
|
|
||||||
// The service UUID
|
// The service UUID
|
||||||
|
@ -92,11 +96,11 @@ public class BluetoothService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get characteristic based on {@link UUID}
|
* Get characteristic based on {@link UUID}, null if it is not known
|
||||||
*
|
*
|
||||||
* @return the {@link BluetoothCharacteristic} with the requested {@link UUID}
|
* @return the {@link BluetoothCharacteristic} with the requested {@link UUID}
|
||||||
*/
|
*/
|
||||||
public BluetoothCharacteristic getCharacteristic(UUID uuid) {
|
public @Nullable BluetoothCharacteristic getCharacteristic(UUID uuid) {
|
||||||
return supportedCharacteristics.get(uuid);
|
return supportedCharacteristics.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +189,7 @@ public class BluetoothService {
|
||||||
* @param handle the handle of the characteristic to return
|
* @param handle the handle of the characteristic to return
|
||||||
* @return return the {@link BluetoothCharacteristic} or null if not found
|
* @return return the {@link BluetoothCharacteristic} or null if not found
|
||||||
*/
|
*/
|
||||||
public BluetoothCharacteristic getCharacteristicByHandle(int handle) {
|
public @Nullable BluetoothCharacteristic getCharacteristicByHandle(int handle) {
|
||||||
synchronized (supportedCharacteristics) {
|
synchronized (supportedCharacteristics) {
|
||||||
for (BluetoothCharacteristic characteristic : supportedCharacteristics.values()) {
|
for (BluetoothCharacteristic characteristic : supportedCharacteristics.values()) {
|
||||||
if (characteristic.getHandle() == handle) {
|
if (characteristic.getHandle() == handle) {
|
||||||
|
@ -201,7 +205,7 @@ public class BluetoothService {
|
||||||
*
|
*
|
||||||
* @return the {@link GattService} relating to this service
|
* @return the {@link GattService} relating to this service
|
||||||
*/
|
*/
|
||||||
public GattService getService() {
|
public @Nullable GattService getService() {
|
||||||
return GattService.getService(uuid);
|
return GattService.getService(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +245,7 @@ public class BluetoothService {
|
||||||
USER_DATA(0x181C),
|
USER_DATA(0x181C),
|
||||||
WEIGHT_SCALE(0x181D);
|
WEIGHT_SCALE(0x181D);
|
||||||
|
|
||||||
private static Map<UUID, GattService> uuidToServiceMapping;
|
private static @Nullable Map<UUID, GattService> uuidToServiceMapping;
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
|
@ -249,18 +253,16 @@ public class BluetoothService {
|
||||||
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initMapping() {
|
public static @Nullable GattService getService(UUID uuid) {
|
||||||
uuidToServiceMapping = new HashMap<>();
|
Map<UUID, GattService> localServiceMapping = uuidToServiceMapping;
|
||||||
for (GattService s : values()) {
|
if (localServiceMapping == null) {
|
||||||
uuidToServiceMapping.put(s.uuid, s);
|
localServiceMapping = new HashMap<>();
|
||||||
|
for (GattService s : values()) {
|
||||||
|
localServiceMapping.put(s.uuid, s);
|
||||||
|
}
|
||||||
|
uuidToServiceMapping = localServiceMapping;
|
||||||
}
|
}
|
||||||
}
|
return localServiceMapping.get(uuid);
|
||||||
|
|
||||||
public static GattService getService(UUID uuid) {
|
|
||||||
if (uuidToServiceMapping == null) {
|
|
||||||
initMapping();
|
|
||||||
}
|
|
||||||
return uuidToServiceMapping.get(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,8 @@ package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Connor Petty - Initial Contribution
|
* @author Connor Petty - Initial Contribution
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothUtils {
|
public class BluetoothUtils {
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(BluetoothUtils.class);
|
public static final Logger logger = LoggerFactory.getLogger(BluetoothUtils.class);
|
||||||
|
@ -43,20 +46,12 @@ public class BluetoothUtils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int[] toIntArray(byte[] value) {
|
public static int[] toIntArray(byte[] value) {
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int[] ret = new int[value.length];
|
int[] ret = new int[value.length];
|
||||||
for (int i = 0; i < value.length; i++) {
|
System.arraycopy(value, 0, ret, 0, value.length);
|
||||||
ret[i] = value[i];
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] toByteArray(int[] value) {
|
public static byte[] toByteArray(int[] value) {
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
byte[] ret = new byte[value.length];
|
byte[] ret = new byte[value.length];
|
||||||
for (int i = 0; i < value.length; i++) {
|
for (int i = 0; i < value.length; i++) {
|
||||||
ret[i] = (byte) (value[i] & 0xFF);
|
ret[i] = (byte) (value[i] & 0xFF);
|
||||||
|
@ -68,7 +63,7 @@ public class BluetoothUtils {
|
||||||
* Return the stored value of this characteristic.
|
* Return the stored value of this characteristic.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Integer getIntegerValue(byte[] value, int formatType, int offset) {
|
public static @Nullable Integer getIntegerValue(byte[] value, int formatType, int offset) {
|
||||||
if ((offset + getTypeLen(formatType)) > value.length) {
|
if ((offset + getTypeLen(formatType)) > value.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +98,7 @@ public class BluetoothUtils {
|
||||||
* Return the stored value of this characteristic. This doesn't read the remote data.
|
* Return the stored value of this characteristic. This doesn't read the remote data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Float getFloatValue(byte[] value, int formatType, int offset) {
|
public static @Nullable Float getFloatValue(byte[] value, int formatType, int offset) {
|
||||||
if ((offset + getTypeLen(formatType)) > value.length) {
|
if ((offset + getTypeLen(formatType)) > value.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +119,8 @@ public class BluetoothUtils {
|
||||||
* Return the stored value of this characteristic. This doesn't read the remote data.
|
* Return the stored value of this characteristic. This doesn't read the remote data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static String getStringValue(byte[] value, int offset) {
|
public static @Nullable String getStringValue(byte[] value, int offset) {
|
||||||
if (value == null || offset > value.length) {
|
if (offset > value.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte[] strBytes = new byte[value.length - offset];
|
byte[] strBytes = new byte[value.length - offset];
|
||||||
|
@ -145,7 +140,7 @@ public class BluetoothUtils {
|
||||||
*/
|
*/
|
||||||
public static boolean setValue(byte[] dest, int value, int formatType, int offset) {
|
public static boolean setValue(byte[] dest, int value, int formatType, int offset) {
|
||||||
int len = offset + getTypeLen(formatType);
|
int len = offset + getTypeLen(formatType);
|
||||||
if (dest == null || len > dest.length) {
|
if (len > dest.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int val = value;
|
int val = value;
|
||||||
|
@ -193,7 +188,7 @@ public class BluetoothUtils {
|
||||||
*/
|
*/
|
||||||
public static boolean setValue(byte[] dest, int mantissa, int exponent, int formatType, int offset) {
|
public static boolean setValue(byte[] dest, int mantissa, int exponent, int formatType, int offset) {
|
||||||
int len = offset + getTypeLen(formatType);
|
int len = offset + getTypeLen(formatType);
|
||||||
if (dest == null || len > dest.length) {
|
if (len > dest.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ public class ConnectedBluetoothHandler extends BeaconBluetoothHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
// super.initialize adds callbacks that might require the connectionTaskExecutor to be present, so we initialize
|
// super.initialize adds callbacks that might require the connectionTaskExecutor to be present, so we initialize
|
||||||
// the connectionTaskExecutor first
|
// the connectionTaskExecutor first
|
||||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1,
|
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth.discovery;
|
package org.openhab.binding.bluetooth.discovery;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.bluetooth.BluetoothCompanyIdentifiers;
|
import org.openhab.binding.bluetooth.BluetoothCompanyIdentifiers;
|
||||||
|
@ -29,7 +28,7 @@ import org.openhab.binding.bluetooth.DelegateBluetoothDevice;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
|
public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
|
||||||
|
|
||||||
private BluetoothDevice delegate;
|
private @NonNullByDefault({}) BluetoothDevice delegate;
|
||||||
|
|
||||||
protected @Nullable String model;
|
protected @Nullable String model;
|
||||||
protected @Nullable String serialNumber;
|
protected @Nullable String serialNumber;
|
||||||
|
@ -43,7 +42,7 @@ public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @NonNull BluetoothDevice getDelegate() {
|
protected @Nullable BluetoothDevice getDelegate() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,10 +202,7 @@ public class BluetoothDeviceSnapshot extends BluetoothDiscoveryDevice {
|
||||||
if (!Objects.equals(firmwareRevision, other.firmwareRevision)) {
|
if (!Objects.equals(firmwareRevision, other.firmwareRevision)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Objects.equals(softwareRevision, other.softwareRevision)) {
|
return Objects.equals(softwareRevision, other.softwareRevision);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -221,7 +221,10 @@ public class BluetoothDiscoveryProcess implements Supplier<DiscoveryResult> {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
byte[] value = device.readCharacteristic(characteristic).get(1, TimeUnit.SECONDS);
|
byte[] value = device.readCharacteristic(characteristic).get(1, TimeUnit.SECONDS);
|
||||||
consumer.accept(BluetoothUtils.getStringValue(value, 0));
|
String strValue = BluetoothUtils.getStringValue(value, 0);
|
||||||
|
if (strValue != null) {
|
||||||
|
consumer.accept(strValue);
|
||||||
|
}
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
logger.debug("Failed to aquire uuid {} from device {}: {}", uuid, device.getAddress(), e.getMessage());
|
logger.debug("Failed to aquire uuid {} from device {}: {}", uuid, device.getAddress(), e.getMessage());
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
|
|
|
@ -190,7 +190,11 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
|
||||||
// we remove any discoveries that have been published for this device
|
// we remove any discoveries that have been published for this device
|
||||||
BluetoothAdapter adapter = device.getAdapter();
|
BluetoothAdapter adapter = device.getAdapter();
|
||||||
if (discoveryFutures.containsKey(adapter)) {
|
if (discoveryFutures.containsKey(adapter)) {
|
||||||
discoveryFutures.remove(adapter).future.thenAccept(result -> retractDiscoveryResult(adapter, result));
|
@Nullable
|
||||||
|
SnapshotFuture ssFuture = discoveryFutures.remove(adapter);
|
||||||
|
if (ssFuture != null) {
|
||||||
|
ssFuture.future.thenAccept(result -> retractDiscoveryResult(adapter, result));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (discoveryFutures.isEmpty()) {
|
if (discoveryFutures.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -253,6 +257,8 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
|
||||||
if (discoveryFutures.containsKey(adapter)) {
|
if (discoveryFutures.containsKey(adapter)) {
|
||||||
// now we need to make sure that we remove the old discovered result if it is different from the new
|
// now we need to make sure that we remove the old discovered result if it is different from the new
|
||||||
// one.
|
// one.
|
||||||
|
|
||||||
|
@Nullable
|
||||||
SnapshotFuture oldSF = discoveryFutures.get(adapter);
|
SnapshotFuture oldSF = discoveryFutures.get(adapter);
|
||||||
future = oldSF.future.thenCombine(future, (oldResult, newResult) -> {
|
future = oldSF.future.thenCombine(future, (oldResult, newResult) -> {
|
||||||
logger.trace("\n old: {}\n new: {}", oldResult, newResult);
|
logger.trace("\n old: {}\n new: {}", oldResult, newResult);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth.notification;
|
package org.openhab.binding.bluetooth.notification;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.bluetooth.BluetoothDevice.ConnectionState;
|
import org.openhab.binding.bluetooth.BluetoothDevice.ConnectionState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +20,7 @@ import org.openhab.binding.bluetooth.BluetoothDevice.ConnectionState;
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothConnectionStatusNotification extends BluetoothNotification {
|
public class BluetoothConnectionStatusNotification extends BluetoothNotification {
|
||||||
private ConnectionState connectionState;
|
private ConnectionState connectionState;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth.notification;
|
package org.openhab.binding.bluetooth.notification;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.bluetooth.BluetoothAddress;
|
import org.openhab.binding.bluetooth.BluetoothAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,13 +21,15 @@ import org.openhab.binding.bluetooth.BluetoothAddress;
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public abstract class BluetoothNotification {
|
public abstract class BluetoothNotification {
|
||||||
protected BluetoothAddress address;
|
|
||||||
|
protected @Nullable BluetoothAddress address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bluetooth address for this frame
|
* Returns the bluetooth address for this frame
|
||||||
*/
|
*/
|
||||||
public BluetoothAddress getAddress() {
|
public @Nullable BluetoothAddress getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,18 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth.notification;
|
package org.openhab.binding.bluetooth.notification;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link BluetoothScanNotification} provides a notification of a received scan packet
|
* The {@link BluetoothScanNotification} provides a notification of a received scan packet
|
||||||
*
|
*
|
||||||
* @author Chris Jackson - Initial contribution
|
* @author Chris Jackson - Initial contribution
|
||||||
* @author Peter Rosenberg - Add support for ServiceData
|
* @author Peter Rosenberg - Add support for ServiceData
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothScanNotification extends BluetoothNotification {
|
public class BluetoothScanNotification extends BluetoothNotification {
|
||||||
/**
|
/**
|
||||||
* The receive signal strength for this beacon packet
|
* The receive signal strength for this beacon packet
|
||||||
|
@ -29,19 +33,19 @@ public class BluetoothScanNotification extends BluetoothNotification {
|
||||||
/**
|
/**
|
||||||
* The raw data
|
* The raw data
|
||||||
*/
|
*/
|
||||||
private byte[] data = null;
|
private byte[] data = new byte[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The manufacturer specific data
|
* The manufacturer specific data
|
||||||
*/
|
*/
|
||||||
private byte[] manufacturerData = null;
|
private byte[] manufacturerData = new byte[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service data.
|
* The service data.
|
||||||
* Key: UUID of the service
|
* Key: UUID of the service
|
||||||
* Value: Data of the characteristic
|
* Value: Data of the characteristic
|
||||||
*/
|
*/
|
||||||
private Map<String, byte[]> serviceData = null;
|
private Map<String, byte[]> serviceData = new HashMap<String, byte[]>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The beacon type
|
* The beacon type
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.bluetooth.util;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a n string utility class
|
||||||
|
*
|
||||||
|
* @author Leo Siepel - Initial contribution
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class StringUtil {
|
||||||
|
|
||||||
|
public static String randomString(int length, String charset) {
|
||||||
|
StringBuilder sb = new StringBuilder(length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int index = (int) (charset.length() * Math.random());
|
||||||
|
sb.append(charset.charAt(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomAlphabetic(int length) {
|
||||||
|
return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomHex(int length) {
|
||||||
|
return StringUtil.randomString(length, "0123456789ABCDEF");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomAlphanummeric(int length) {
|
||||||
|
return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz");
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||||
*
|
*
|
||||||
* @author Kai Kreuzer - Initial contribution
|
* @author Kai Kreuzer - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class BluetoothAddressTest {
|
public class BluetoothAddressTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||||
*
|
*
|
||||||
* @author Peter Rosenberg - Initial contribution
|
* @author Peter Rosenberg - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
public class CharacteristicPropertiesTest {
|
public class CharacteristicPropertiesTest {
|
||||||
private BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.randomUUID(), 0);
|
private BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.randomUUID(), 0);
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.bluetooth;
|
package org.openhab.binding.bluetooth;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.openhab.binding.bluetooth.util.StringUtil;
|
||||||
import org.openhab.core.thing.ThingUID;
|
import org.openhab.core.thing.ThingUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,14 +27,14 @@ public class TestUtils {
|
||||||
public static BluetoothAddress randomAddress() {
|
public static BluetoothAddress randomAddress() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
builder.append(RandomStringUtils.random(2, "0123456789ABCDEF"));
|
builder.append(StringUtil.randomHex(2));
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
}
|
}
|
||||||
builder.append(RandomStringUtils.random(2, "0123456789ABCDEF"));
|
builder.append(StringUtil.randomHex(2));
|
||||||
return new BluetoothAddress(builder.toString());
|
return new BluetoothAddress(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ThingUID randomThingUID() {
|
public static ThingUID randomThingUID() {
|
||||||
return new ThingUID(BluetoothBindingConstants.BINDING_ID, RandomStringUtils.randomAlphabetic(6));
|
return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -49,13 +47,12 @@ import org.openhab.binding.bluetooth.TestUtils;
|
||||||
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
|
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
|
||||||
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryParticipant;
|
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryParticipant;
|
||||||
import org.openhab.binding.bluetooth.notification.BluetoothConnectionStatusNotification;
|
import org.openhab.binding.bluetooth.notification.BluetoothConnectionStatusNotification;
|
||||||
|
import org.openhab.binding.bluetooth.util.StringUtil;
|
||||||
import org.openhab.core.config.discovery.DiscoveryListener;
|
import org.openhab.core.config.discovery.DiscoveryListener;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
||||||
import org.openhab.core.thing.ThingTypeUID;
|
import org.openhab.core.thing.ThingTypeUID;
|
||||||
import org.openhab.core.thing.ThingUID;
|
import org.openhab.core.thing.ThingUID;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link BluetoothDiscoveryService}.
|
* Tests {@link BluetoothDiscoveryService}.
|
||||||
|
@ -69,8 +66,6 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
|
|
||||||
private static final int TIMEOUT = 2000;
|
private static final int TIMEOUT = 2000;
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(BluetoothDiscoveryServiceTest.class);
|
|
||||||
|
|
||||||
private @NonNullByDefault({}) BluetoothDiscoveryService discoveryService;
|
private @NonNullByDefault({}) BluetoothDiscoveryService discoveryService;
|
||||||
|
|
||||||
private @Spy @NonNullByDefault({}) MockDiscoveryParticipant participant1 = new MockDiscoveryParticipant();
|
private @Spy @NonNullByDefault({}) MockDiscoveryParticipant participant1 = new MockDiscoveryParticipant();
|
||||||
|
@ -201,7 +196,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
|
|
||||||
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
|
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
|
||||||
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);
|
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);
|
||||||
String deviceName = RandomStringUtils.randomAlphanumeric(10);
|
String deviceName = StringUtil.randomAlphanummeric(10);
|
||||||
mockDevice.setDeviceName(deviceName);
|
mockDevice.setDeviceName(deviceName);
|
||||||
|
|
||||||
BluetoothDevice device = Mockito.spy(mockDevice);
|
BluetoothDevice device = Mockito.spy(mockDevice);
|
||||||
|
@ -228,7 +223,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
|
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
|
||||||
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
|
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
|
||||||
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
|
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
|
||||||
String deviceName = RandomStringUtils.randomAlphanumeric(10);
|
String deviceName = StringUtil.randomAlphanummeric(10);
|
||||||
mockDevice1.setDeviceName(deviceName);
|
mockDevice1.setDeviceName(deviceName);
|
||||||
mockDevice2.setDeviceName(deviceName);
|
mockDevice2.setDeviceName(deviceName);
|
||||||
|
|
||||||
|
@ -266,7 +261,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
public void nonConnectionParticipantTest() {
|
public void nonConnectionParticipantTest() {
|
||||||
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
|
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
|
||||||
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());
|
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());
|
||||||
String deviceName = RandomStringUtils.randomAlphanumeric(10);
|
String deviceName = StringUtil.randomAlphanummeric(10);
|
||||||
mockDevice.setDeviceName(deviceName);
|
mockDevice.setDeviceName(deviceName);
|
||||||
|
|
||||||
BluetoothDevice device = Mockito.spy(mockDevice);
|
BluetoothDevice device = Mockito.spy(mockDevice);
|
||||||
|
@ -423,7 +418,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
|
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
|
||||||
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
|
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
|
||||||
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
|
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
|
||||||
String deviceName = RandomStringUtils.randomAlphanumeric(10);
|
String deviceName = StringUtil.randomAlphanummeric(10);
|
||||||
|
|
||||||
MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {
|
MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -539,8 +534,7 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
private ThingTypeUID typeUID;
|
private ThingTypeUID typeUID;
|
||||||
|
|
||||||
public MockDiscoveryParticipant() {
|
public MockDiscoveryParticipant() {
|
||||||
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID,
|
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
|
||||||
RandomStringUtils.randomAlphabetic(6));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -550,16 +544,20 @@ public class BluetoothDiscoveryServiceTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) {
|
public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) {
|
||||||
String repProp = RandomStringUtils.randomAlphabetic(6);
|
String repProp = StringUtil.randomAlphabetic(6);
|
||||||
return DiscoveryResultBuilder.create(getThingUID(device)).withLabel(RandomStringUtils.randomAlphabetic(6))
|
ThingUID thingUID = getThingUID(device);
|
||||||
.withProperty(repProp, RandomStringUtils.randomAlphabetic(6)).withRepresentationProperty(repProp)
|
if (thingUID == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return DiscoveryResultBuilder.create(thingUID).withLabel(StringUtil.randomAlphabetic(6))
|
||||||
|
.withProperty(repProp, StringUtil.randomAlphabetic(6)).withRepresentationProperty(repProp)
|
||||||
.withBridge(device.getAdapter().getUID()).build();
|
.withBridge(device.getAdapter().getUID()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ThingUID getThingUID(BluetoothDiscoveryDevice device) {
|
public @Nullable ThingUID getThingUID(BluetoothDiscoveryDevice device) {
|
||||||
String deviceName = device.getName();
|
String deviceName = device.getName();
|
||||||
String id = deviceName != null ? deviceName : RandomStringUtils.randomAlphabetic(6);
|
String id = deviceName != null ? deviceName : StringUtil.randomAlphabetic(6);
|
||||||
return new ThingUID(typeUID, device.getAdapter().getUID(), id);
|
return new ThingUID(typeUID, device.getAdapter().getUID(), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -33,10 +34,11 @@ import org.openhab.core.common.NamedThreadFactory;
|
||||||
* @author Connor Petty - Initial contribution
|
* @author Connor Petty - Initial contribution
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
class RetryFutureTest {
|
class RetryFutureTest {
|
||||||
|
|
||||||
private static final int TIMEOUT_MS = 1000;
|
private static final int TIMEOUT_MS = 1000;
|
||||||
private ScheduledExecutorService scheduler;
|
private @NonNullByDefault({}) ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void init() {
|
public void init() {
|
||||||
|
@ -165,6 +167,6 @@ class RetryFutureTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DummyException extends Exception {
|
private static class DummyException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue