Skip to content

Commit

Permalink
[bluetooth.govee] null annotations (openhab#13978)
Browse files Browse the repository at this point in the history
* null annotations and checkstyle
* Fix more warnings

Signed-off-by: lsiepel <leosiepel@gmail.com>
  • Loading branch information
lsiepel authored and nemerdaud committed Feb 28, 2023
1 parent b4d334d commit 80bb7ae
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
*/
package org.openhab.binding.bluetooth.gattserial;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* @author Connor Petty - Initial Contribution
*
*/
@NonNullByDefault
public interface MessageSupplier<M extends GattMessage> {

public M createMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public void dispose() {
}

private CompletableFuture<@Nullable ?> createInitSettingsJob() {

logger.debug("Initializing Govee Hygrometer {} settings", address);

QuantityType<Temperature> temCali = config.getTemperatureCalibration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum GoveeModel {
private final String label;
private final boolean supportsWarningBroadcast;

private final static Logger logger = LoggerFactory.getLogger(GoveeModel.class);
private static final Logger logger = LoggerFactory.getLogger(GoveeModel.class);

private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
this.thingTypeUID = thingTypeUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public byte getCommandCode() {
return 3;
}

private static short convertQuantity(QuantityType<Dimensionless> quantity) {
var percentQuantity = quantity.toUnit(Units.PERCENT);
private static short convertQuantity(@Nullable QuantityType<Dimensionless> quantity) {
if (quantity == null) {
throw new IllegalArgumentException("Unable to convert quantity to percent");
}
QuantityType<Dimensionless> percentQuantity = quantity.toUnit(Units.PERCENT);
if (percentQuantity == null) {
throw new IllegalArgumentException("Unable to convert quantity to percent");
}
Expand All @@ -65,14 +68,15 @@ private static short convertQuantity(QuantityType<Dimensionless> quantity) {

@Override
protected byte @Nullable [] getData() {
if (settings == null) {
WarningSettingsDTO<Dimensionless> localSettins = settings;
if (localSettins == null || localSettins.min == null || localSettins.max == null) {
return null;
}

ByteBuffer buffer = ByteBuffer.allocate(5).order(ByteOrder.LITTLE_ENDIAN);
buffer.put(settings.enableAlarm == OnOffType.ON ? (byte) 1 : 0);
buffer.putShort(convertQuantity(settings.min));
buffer.putShort(convertQuantity(settings.max));
buffer.put(localSettins.enableAlarm == OnOffType.ON ? (byte) 1 : 0);
buffer.putShort(convertQuantity(localSettins.min));
buffer.putShort(convertQuantity(localSettins.max));
return buffer.array();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openhab.binding.bluetooth.MockBluetoothAdapter;
import org.openhab.binding.bluetooth.MockBluetoothDevice;
Expand All @@ -40,7 +41,8 @@ void noMatchTest() {
}

@Test
void testGovee_H5074_84DD() {
@DisplayName("testGovee_H5074_84DD")
void testGoveeH507484DD() {
MockBluetoothAdapter adapter = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = adapter.getDevice(TestUtils.randomAddress());
mockDevice.setName("Govee_H5074_84DD");
Expand All @@ -49,7 +51,8 @@ void testGovee_H5074_84DD() {
}

@Test
void testGVH5102_77E9() {
@DisplayName("testGVH5102_77E9")
void testGVH510277E9() {
MockBluetoothAdapter adapter = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = adapter.getDevice(TestUtils.randomAddress());
mockDevice.setName("GVH5102_77E9");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.bluetooth.govee.internal.GoveeModel;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand All @@ -36,10 +38,10 @@
* @author Connor Petty - Initial contribution
*
*/
@NonNullByDefault
public class ThingTypeTableGenerator {

public static void main(String[] args) throws Exception {

FileInputStream fileIS = new FileInputStream("src/main/resources/OH-INF/thing/thing-types.xml");
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Expand Down Expand Up @@ -111,9 +113,9 @@ private static int maxColumnSize(List<String[]> rows, int column) {
}

private static class ThingTypeData {
private String id;
private String label;
private String description;
private @Nullable String id;
private @Nullable String label;
private @Nullable String description;
}

private static String[] toRow(ThingTypeData data) {
Expand All @@ -122,7 +124,7 @@ private static String[] toRow(ThingTypeData data) {
modelsForType(data.id).stream().map(model -> model.name()).collect(Collectors.joining(",")) };
}

private static List<GoveeModel> modelsForType(String typeUID) {
private static List<GoveeModel> modelsForType(@Nullable String typeUID) {
return Arrays.stream(GoveeModel.values()).filter(model -> model.getThingTypeUID().getId().equals(typeUID))
.collect(Collectors.toList());
}
Expand Down

0 comments on commit 80bb7ae

Please sign in to comment.