]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth.govee] null annotations (#13978)
authorlsiepel <leosiepel@gmail.com>
Thu, 22 Dec 2022 07:58:12 +0000 (08:58 +0100)
committerGitHub <noreply@github.com>
Thu, 22 Dec 2022 07:58:12 +0000 (08:58 +0100)
* null annotations and checkstyle
* Fix more warnings

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/gattserial/MessageSupplier.java
bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeHygrometerHandler.java
bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java
bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/command/hygrometer/GetOrSetHumWarningCommand.java
bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java
bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/readme/ThingTypeTableGenerator.java

index a1b90deb22ea12949e7e33b2e519f3b3a9273e22..6a2aa337f401a5f23723e3f3ed558b27ddb33164 100644 (file)
  */
 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();
index 7743dc1c914d9d48e14ce9da50401e11db6d7459..b5d9d67029abe0ed1ba2cfd88b466f5be29bfc55 100644 (file)
@@ -151,7 +151,6 @@ public class GoveeHygrometerHandler extends ConnectedBluetoothHandler {
     }
 
     private CompletableFuture<@Nullable ?> createInitSettingsJob() {
-
         logger.debug("Initializing Govee Hygrometer {} settings", address);
 
         QuantityType<Temperature> temCali = config.getTemperatureCalibration();
index 8002aff39c699fdbba9d1ebe5c5d7a5cf0a10d4d..aa814959d9339884107b537be3a1b5af1f64c93a 100644 (file)
@@ -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;
index 6c4195feb6dc909667ae4bc29185ea5408d9a676..4cb01d2ae4eb93f057b73553ece9ae830813dc34 100644 (file)
@@ -55,8 +55,11 @@ public class GetOrSetHumWarningCommand extends GoveeCommand {
         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");
         }
@@ -65,14 +68,15 @@ public class GetOrSetHumWarningCommand extends GoveeCommand {
 
     @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();
     }
 
index 5d9042c39cdcdf3c2e4383087b3f2d026f7aabc3..9d63653c89186ce0a02fbc969bb10d2c19cb1fd6 100644 (file)
@@ -14,6 +14,7 @@ package org.openhab.binding.bluetooth.govee.internal;
 
 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;
@@ -40,7 +41,8 @@ class GoveeModelTest {
     }
 
     @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");
@@ -49,7 +51,8 @@ class GoveeModelTest {
     }
 
     @Test
-    void testGVH5102_77E9() {
+    @DisplayName("testGVH5102_77E9")
+    void testGVH510277E9() {
         MockBluetoothAdapter adapter = new MockBluetoothAdapter();
         MockBluetoothDevice mockDevice = adapter.getDevice(TestUtils.randomAddress());
         mockDevice.setName("GVH5102_77E9");
index dc17a83eb28ac6b18321d09f6f9a9582c9c1ba0e..095c25e842de87c1d3df438c74bea6e7a981b78d 100644 (file)
@@ -27,6 +27,8 @@ import javax.xml.xpath.XPathConstants;
 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;
@@ -36,10 +38,10 @@ import org.w3c.dom.NodeList;
  * @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();
@@ -111,9 +113,9 @@ public class ThingTypeTableGenerator {
     }
 
     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) {
@@ -122,7 +124,7 @@ public class ThingTypeTableGenerator {
                 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());
     }