]> git.basschouten.com Git - openhab-addons.git/commitdiff
[govee] Fix Govee H5102 detection (#12373)
authorDavid <1133989+davidoe@users.noreply.github.com>
Sat, 26 Feb 2022 13:14:33 +0000 (14:14 +0100)
committerGitHub <noreply@github.com>
Sat, 26 Feb 2022 13:14:33 +0000 (14:14 +0100)
Signed-off-by: davidoe <1133989+davidoe@users.noreply.github.com>
bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java
bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java

index 87f1707c476d0a000447658aed68d08d7a067a15..8002aff39c699fdbba9d1ebe5c5d7a5cf0a10d4d 100644 (file)
@@ -18,6 +18,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
 import org.openhab.core.thing.ThingTypeUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Connor Petty - Initial contribution
@@ -42,6 +44,8 @@ public enum GoveeModel {
     private final String label;
     private final boolean supportsWarningBroadcast;
 
+    private final static Logger logger = LoggerFactory.getLogger(GoveeModel.class);
+
     private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
         this.thingTypeUID = thingTypeUID;
         this.label = label;
@@ -63,15 +67,17 @@ public enum GoveeModel {
     public static @Nullable GoveeModel getGoveeModel(BluetoothDiscoveryDevice device) {
         String name = device.getName();
         if (name != null) {
-            if (name.startsWith("Govee") && name.length() >= 11) {
+            if ((name.startsWith("Govee") && name.length() >= 11) || name.startsWith("GVH")) {
                 String uname = name.toUpperCase();
                 for (GoveeModel model : GoveeModel.values()) {
                     if (uname.contains(model.name())) {
+                        logger.debug("detected model {}", model);
                         return model;
                     }
                 }
             }
         }
+        logger.debug("Device {} is no Govee", name);
         return null;
     }
 }
index 8d382ed00d38a92d2bf8772fe1cedab54a0764ee..5d9042c39cdcdf3c2e4383087b3f2d026f7aabc3 100644 (file)
@@ -47,4 +47,13 @@ class GoveeModelTest {
 
         Assertions.assertEquals(GoveeModel.H5074, GoveeModel.getGoveeModel(new BluetoothDiscoveryDevice(mockDevice)));
     }
+
+    @Test
+    void testGVH5102_77E9() {
+        MockBluetoothAdapter adapter = new MockBluetoothAdapter();
+        MockBluetoothDevice mockDevice = adapter.getDevice(TestUtils.randomAddress());
+        mockDevice.setName("GVH5102_77E9");
+
+        Assertions.assertEquals(GoveeModel.H5102, GoveeModel.getGoveeModel(new BluetoothDiscoveryDevice(mockDevice)));
+    }
 }