From fa40dd8b9bd348460b32bdc5effdd011ca40ad9b Mon Sep 17 00:00:00 2001 From: davidoe <1133989+davidoe@users.noreply.github.com> Date: Fri, 25 Feb 2022 20:15:25 +0100 Subject: [PATCH] fix Govee H5102 detection Signed-off-by: davidoe <1133989+davidoe@users.noreply.github.com> --- .../binding/bluetooth/govee/internal/GoveeModel.java | 8 +++++++- .../binding/bluetooth/govee/internal/GoveeModelTest.java | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java b/bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java index 87f1707c476d0..8002aff39c699 100644 --- a/bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java +++ b/bundles/org.openhab.binding.bluetooth.govee/src/main/java/org/openhab/binding/bluetooth/govee/internal/GoveeModel.java @@ -18,6 +18,8 @@ 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 boolean supportsWarningBroadcast() { 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; } } diff --git a/bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java b/bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java index 8d382ed00d38a..5d9042c39cdcd 100644 --- a/bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java +++ b/bundles/org.openhab.binding.bluetooth.govee/src/test/java/org/openhab/binding/bluetooth/govee/internal/GoveeModelTest.java @@ -47,4 +47,13 @@ void testGovee_H5074_84DD() { 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))); + } }