*/
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
*
* @author Chris Jackson - Initial contribution
*/
+@NonNullByDefault
public class BluetoothAddress {
public static final int BD_ADDRESS_LENGTH = 17;
*
* @param address the device address
*/
- public BluetoothAddress(String address) {
+ public BluetoothAddress(@Nullable String address) {
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");
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((address == null) ? 0 : address.hashCode());
+ result = prime * result + address.hashCode();
return result;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
return false;
}
BluetoothAddress other = (BluetoothAddress) obj;
- if (address == null) {
- if (other.address != null) {
- return false;
- }
- } else if (!address.equals(other.address)) {
- return false;
- }
- return true;
+
+ return address.equals(other.address);
}
@Override
import java.util.Map;
import java.util.UUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link BluetoothCharacteristic} class defines the Bluetooth characteristic.
* @author Kai Kreuzer - Cleaned up code
* @author Peter Rosenberg - Improve properties support
*/
+@NonNullByDefault
public class BluetoothCharacteristic {
public static final int PROPERTY_BROADCAST = 0x01;
public static final int PROPERTY_READ = 0x02;
public static final int WRITE_TYPE_NO_RESPONSE = 0x01;
public static final int WRITE_TYPE_SIGNED = 0x04;
- private final Logger logger = LoggerFactory.getLogger(BluetoothCharacteristic.class);
-
/**
* The {@link UUID} for this characteristic
*/
/**
* The {@link BluetoothService} to which this characteristic belongs
*/
- protected BluetoothService service;
+ protected @Nullable BluetoothService service;
/**
* Create a new BluetoothCharacteristic.
*
* @return the {@link BluetoothService}
*/
- public BluetoothService getService() {
+ public @Nullable BluetoothService getService() {
return service;
}
*
* @return the {@link BluetoothDescriptor}
*/
- public BluetoothDescriptor getDescriptor(UUID uuid) {
+ public @Nullable BluetoothDescriptor getDescriptor(UUID uuid) {
return gattDescriptors.get(uuid);
}
@Override
public int hashCode() {
+ BluetoothService btService = service;
final int prime = 31;
int result = 1;
result = prime * result + instance;
- result = prime * result + ((service == null) ? 0 : service.hashCode());
- result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
+ result = prime * result + ((btService == null) ? 0 : btService.hashCode());
+ result = prime * result + uuid.hashCode();
return result;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (instance != other.instance) {
return false;
}
- if (service == null) {
+ BluetoothService btService = service;
+ if (btService == null) {
if (other.service != null) {
return false;
}
- } else if (!service.equals(other.service)) {
- return false;
- }
- if (uuid == null) {
- if (other.uuid != null) {
- return false;
- }
- } else if (!uuid.equals(other.uuid)) {
+ } else if (!btService.equals(other.service)) {
return false;
}
- return true;
+
+ return uuid.equals(other.uuid);
}
- public GattCharacteristic getGattCharacteristic() {
+ public @Nullable GattCharacteristic getGattCharacteristic() {
return GattCharacteristic.getCharacteristic(uuid);
}
REMOVABLE(0x2A3A),
SERVICE_REQUIRED(0x2A3B);
- private static Map<UUID, GattCharacteristic> uuidToServiceMapping;
+ private static @Nullable Map<UUID, GattCharacteristic> uuidToServiceMapping;
private UUID uuid;
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
}
- private static void initMapping() {
- uuidToServiceMapping = new HashMap<>();
- for (GattCharacteristic s : values()) {
- uuidToServiceMapping.put(s.uuid, s);
- }
- }
-
- public static GattCharacteristic getCharacteristic(UUID uuid) {
- if (uuidToServiceMapping == null) {
- initMapping();
+ public static @Nullable GattCharacteristic getCharacteristic(UUID uuid) {
+ Map<UUID, GattCharacteristic> localServiceMapping = uuidToServiceMapping;
+ if (localServiceMapping == null) {
+ localServiceMapping = new HashMap<>();
+ for (GattCharacteristic s : values()) {
+ localServiceMapping.put(s.uuid, s);
+ }
+ uuidToServiceMapping = localServiceMapping;
}
- return uuidToServiceMapping.get(uuid);
+ return localServiceMapping.get(uuid);
}
/**
*/
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.
*
* @author Chris Jackson - Initial Contribution
*
*/
+@NonNullByDefault
public class BluetoothClass {
private final int clazz;
*/
package org.openhab.binding.bluetooth;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* An enumeration of transaction completion status values
*
* @author Chris Jackson - Initial contribution
*
*/
+@NonNullByDefault
public enum BluetoothCompletionStatus {
SUCCESS,
ERROR
import java.util.Map;
import java.util.UUID;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
* The {@link BluetoothDescriptor} class defines the Bluetooth descriptor.
* <p>
* @author Chris Jackson - Initial contribution
* @author Kai Kreuzer - added constructor and fixed setValue method
*/
+@NonNullByDefault
public class BluetoothDescriptor {
protected final BluetoothCharacteristic characteristic;
return handle;
}
- public GattDescriptor getDescriptor() {
+ public @Nullable GattDescriptor getDescriptor() {
return GattDescriptor.getDescriptor(uuid);
}
NUMBER_OF_DIGITALS(0x2909),
TRIGGER_SETTING(0x290A);
- private static Map<UUID, GattDescriptor> uuidToServiceMapping;
+ private static @Nullable Map<UUID, GattDescriptor> uuidToServiceMapping;
private final UUID uuid;
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
}
- private static void initMapping() {
- uuidToServiceMapping = new HashMap<>();
- for (GattDescriptor s : values()) {
- uuidToServiceMapping.put(s.uuid, s);
- }
- }
-
- public static GattDescriptor getDescriptor(UUID uuid) {
- if (uuidToServiceMapping == null) {
- initMapping();
+ public static @Nullable GattDescriptor getDescriptor(UUID uuid) {
+ Map<UUID, GattDescriptor> localServiceMapping = uuidToServiceMapping;
+ if (localServiceMapping == null) {
+ localServiceMapping = new HashMap<>();
+ for (GattDescriptor s : values()) {
+ localServiceMapping.put(s.uuid, s);
+ }
+ uuidToServiceMapping = localServiceMapping;
}
- return uuidToServiceMapping.get(uuid);
+ return localServiceMapping.get(uuid);
}
/**
import java.util.UUID;
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.
* <p>
* @author Chris Jackson - Initial contribution
* @author Kai Kreuzer - Cleaned up code
*/
+@NonNullByDefault
public class BluetoothService {
// The service UUID
}
/**
- * 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}
*/
- public BluetoothCharacteristic getCharacteristic(UUID uuid) {
+ public @Nullable BluetoothCharacteristic getCharacteristic(UUID uuid) {
return supportedCharacteristics.get(uuid);
}
* @param handle the handle of the characteristic to return
* @return return the {@link BluetoothCharacteristic} or null if not found
*/
- public BluetoothCharacteristic getCharacteristicByHandle(int handle) {
+ public @Nullable BluetoothCharacteristic getCharacteristicByHandle(int handle) {
synchronized (supportedCharacteristics) {
for (BluetoothCharacteristic characteristic : supportedCharacteristics.values()) {
if (characteristic.getHandle() == handle) {
*
* @return the {@link GattService} relating to this service
*/
- public GattService getService() {
+ public @Nullable GattService getService() {
return GattService.getService(uuid);
}
USER_DATA(0x181C),
WEIGHT_SCALE(0x181D);
- private static Map<UUID, GattService> uuidToServiceMapping;
+ private static @Nullable Map<UUID, GattService> uuidToServiceMapping;
private UUID uuid;
this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
}
- private static void initMapping() {
- uuidToServiceMapping = new HashMap<>();
- for (GattService s : values()) {
- uuidToServiceMapping.put(s.uuid, s);
- }
- }
-
- public static GattService getService(UUID uuid) {
- if (uuidToServiceMapping == null) {
- initMapping();
+ public static @Nullable GattService getService(UUID uuid) {
+ Map<UUID, GattService> localServiceMapping = uuidToServiceMapping;
+ if (localServiceMapping == null) {
+ localServiceMapping = new HashMap<>();
+ for (GattService s : values()) {
+ localServiceMapping.put(s.uuid, s);
+ }
+ uuidToServiceMapping = localServiceMapping;
}
- return uuidToServiceMapping.get(uuid);
+ return localServiceMapping.get(uuid);
}
/**
import java.nio.charset.StandardCharsets;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author Connor Petty - Initial Contribution
*
*/
+@NonNullByDefault
public class BluetoothUtils {
public static final Logger logger = LoggerFactory.getLogger(BluetoothUtils.class);
* @return
*/
public static int[] toIntArray(byte[] value) {
- if (value == null) {
- return null;
- }
int[] ret = new int[value.length];
- for (int i = 0; i < value.length; i++) {
- ret[i] = value[i];
- }
+ System.arraycopy(value, 0, ret, 0, value.length);
return ret;
}
public static byte[] toByteArray(int[] value) {
- if (value == null) {
- return null;
- }
byte[] ret = new byte[value.length];
for (int i = 0; i < value.length; i++) {
ret[i] = (byte) (value[i] & 0xFF);
* 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) {
return null;
}
* 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) {
return null;
}
* Return the stored value of this characteristic. This doesn't read the remote data.
*
*/
- public static String getStringValue(byte[] value, int offset) {
- if (value == null || offset > value.length) {
+ public static @Nullable String getStringValue(byte[] value, int offset) {
+ if (offset > value.length) {
return null;
}
byte[] strBytes = new byte[value.length - offset];
*/
public static boolean setValue(byte[] dest, int value, int formatType, int offset) {
int len = offset + getTypeLen(formatType);
- if (dest == null || len > dest.length) {
+ if (len > dest.length) {
return false;
}
int val = value;
*/
public static boolean setValue(byte[] dest, int mantissa, int exponent, int formatType, int offset) {
int len = offset + getTypeLen(formatType);
- if (dest == null || len > dest.length) {
+ if (len > dest.length) {
return false;
}
@Override
public void initialize() {
-
// super.initialize adds callbacks that might require the connectionTaskExecutor to be present, so we initialize
// the connectionTaskExecutor first
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1,
*/
package org.openhab.binding.bluetooth.discovery;
-import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.bluetooth.BluetoothCompanyIdentifiers;
@NonNullByDefault
public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
- private BluetoothDevice delegate;
+ private @NonNullByDefault({}) BluetoothDevice delegate;
protected @Nullable String model;
protected @Nullable String serialNumber;
}
@Override
- protected @NonNull BluetoothDevice getDelegate() {
+ protected @Nullable BluetoothDevice getDelegate() {
return delegate;
}
if (!Objects.equals(firmwareRevision, other.firmwareRevision)) {
return false;
}
- if (!Objects.equals(softwareRevision, other.softwareRevision)) {
- return false;
- }
- return true;
+ return Objects.equals(softwareRevision, other.softwareRevision);
}
/**
}
try {
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) {
logger.debug("Failed to aquire uuid {} from device {}: {}", uuid, device.getAddress(), e.getMessage());
} catch (TimeoutException e) {
// we remove any discoveries that have been published for this device
BluetoothAdapter adapter = device.getAdapter();
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()) {
return null;
if (discoveryFutures.containsKey(adapter)) {
// now we need to make sure that we remove the old discovered result if it is different from the new
// one.
+
+ @Nullable
SnapshotFuture oldSF = discoveryFutures.get(adapter);
future = oldSF.future.thenCombine(future, (oldResult, newResult) -> {
logger.trace("\n old: {}\n new: {}", oldResult, newResult);
*/
package org.openhab.binding.bluetooth.notification;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.bluetooth.BluetoothDevice.ConnectionState;
/**
*
* @author Chris Jackson - Initial contribution
*/
+@NonNullByDefault
public class BluetoothConnectionStatusNotification extends BluetoothNotification {
private ConnectionState connectionState;
*/
package org.openhab.binding.bluetooth.notification;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.bluetooth.BluetoothAddress;
/**
*
* @author Chris Jackson - Initial contribution
*/
+@NonNullByDefault
public abstract class BluetoothNotification {
- protected BluetoothAddress address;
+
+ protected @Nullable BluetoothAddress address;
/**
* Returns the bluetooth address for this frame
*/
- public BluetoothAddress getAddress() {
+ public @Nullable BluetoothAddress getAddress() {
return address;
}
}
*/
package org.openhab.binding.bluetooth.notification;
+import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* The {@link BluetoothScanNotification} provides a notification of a received scan packet
*
* @author Chris Jackson - Initial contribution
* @author Peter Rosenberg - Add support for ServiceData
*/
+@NonNullByDefault
public class BluetoothScanNotification extends BluetoothNotification {
/**
* The receive signal strength for this beacon packet
/**
* The raw data
*/
- private byte[] data = null;
+ private byte[] data = new byte[0];
/**
* The manufacturer specific data
*/
- private byte[] manufacturerData = null;
+ private byte[] manufacturerData = new byte[0];
/**
* The service data.
* Key: UUID of the service
* Value: Data of the characteristic
*/
- private Map<String, byte[]> serviceData = null;
+ private Map<String, byte[]> serviceData = new HashMap<String, byte[]>();
/**
* The beacon type
--- /dev/null
+/**
+ * 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");
+ }
+}
import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
/**
*
* @author Kai Kreuzer - Initial contribution
*/
+@NonNullByDefault
public class BluetoothAddressTest {
@Test
import java.util.UUID;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
/**
*
* @author Peter Rosenberg - Initial contribution
*/
+@NonNullByDefault
public class CharacteristicPropertiesTest {
private BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.randomUUID(), 0);
*/
package org.openhab.binding.bluetooth;
-import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.bluetooth.util.StringUtil;
import org.openhab.core.thing.ThingUID;
/**
public static BluetoothAddress randomAddress() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 5; i++) {
- builder.append(RandomStringUtils.random(2, "0123456789ABCDEF"));
+ builder.append(StringUtil.randomHex(2));
builder.append(":");
}
- builder.append(RandomStringUtils.random(2, "0123456789ABCDEF"));
+ builder.append(StringUtil.randomHex(2));
return new BluetoothAddress(builder.toString());
}
public static ThingUID randomThingUID() {
- return new ThingUID(BluetoothBindingConstants.BINDING_ID, RandomStringUtils.randomAlphabetic(6));
+ return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
}
}
import java.util.concurrent.atomic.AtomicInteger;
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.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryParticipant;
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.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Tests {@link BluetoothDiscoveryService}.
private static final int TIMEOUT = 2000;
- private final Logger logger = LoggerFactory.getLogger(BluetoothDiscoveryServiceTest.class);
-
private @NonNullByDefault({}) BluetoothDiscoveryService discoveryService;
private @Spy @NonNullByDefault({}) MockDiscoveryParticipant participant1 = new MockDiscoveryParticipant();
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);
- String deviceName = RandomStringUtils.randomAlphanumeric(10);
+ String deviceName = StringUtil.randomAlphanummeric(10);
mockDevice.setDeviceName(deviceName);
BluetoothDevice device = Mockito.spy(mockDevice);
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
- String deviceName = RandomStringUtils.randomAlphanumeric(10);
+ String deviceName = StringUtil.randomAlphanummeric(10);
mockDevice1.setDeviceName(deviceName);
mockDevice2.setDeviceName(deviceName);
public void nonConnectionParticipantTest() {
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());
- String deviceName = RandomStringUtils.randomAlphanumeric(10);
+ String deviceName = StringUtil.randomAlphanummeric(10);
mockDevice.setDeviceName(deviceName);
BluetoothDevice device = Mockito.spy(mockDevice);
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
- String deviceName = RandomStringUtils.randomAlphanumeric(10);
+ String deviceName = StringUtil.randomAlphanummeric(10);
MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {
@Override
private ThingTypeUID typeUID;
public MockDiscoveryParticipant() {
- this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID,
- RandomStringUtils.randomAlphabetic(6));
+ this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
}
@Override
@Override
public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) {
- String repProp = RandomStringUtils.randomAlphabetic(6);
- return DiscoveryResultBuilder.create(getThingUID(device)).withLabel(RandomStringUtils.randomAlphabetic(6))
- .withProperty(repProp, RandomStringUtils.randomAlphabetic(6)).withRepresentationProperty(repProp)
+ String repProp = StringUtil.randomAlphabetic(6);
+ ThingUID thingUID = getThingUID(device);
+ 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();
}
@Override
- public @NonNull ThingUID getThingUID(BluetoothDiscoveryDevice device) {
+ public @Nullable ThingUID getThingUID(BluetoothDiscoveryDevice device) {
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);
}
}
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
* @author Connor Petty - Initial contribution
*
*/
+@NonNullByDefault
class RetryFutureTest {
private static final int TIMEOUT_MS = 1000;
- private ScheduledExecutorService scheduler;
+ private @NonNullByDefault({}) ScheduledExecutorService scheduler;
@BeforeEach
public void init() {
}
private static class DummyException extends Exception {
-
+ private static final long serialVersionUID = 1L;
}
}