[govee] Fix Govee H5102 detection (#12373)

Signed-off-by: davidoe <1133989+davidoe@users.noreply.github.com>
This commit is contained in:
David 2022-02-26 14:14:33 +01:00 committed by GitHub
parent a78f73eecd
commit 38c896edc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View 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;
}
}

View 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)));
}
}