[govee] Fix Govee H5102 detection (#12373)
Signed-off-by: davidoe <1133989+davidoe@users.noreply.github.com>
This commit is contained in:
parent
a78f73eecd
commit
38c896edc5
@ -18,6 +18,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
|
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
|
||||||
import org.openhab.core.thing.ThingTypeUID;
|
import org.openhab.core.thing.ThingTypeUID;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Connor Petty - Initial contribution
|
* @author Connor Petty - Initial contribution
|
||||||
@ -42,6 +44,8 @@ public enum GoveeModel {
|
|||||||
private final String label;
|
private final String label;
|
||||||
private final boolean supportsWarningBroadcast;
|
private final boolean supportsWarningBroadcast;
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(GoveeModel.class);
|
||||||
|
|
||||||
private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
|
private GoveeModel(ThingTypeUID thingTypeUID, String label, boolean supportsWarningBroadcast) {
|
||||||
this.thingTypeUID = thingTypeUID;
|
this.thingTypeUID = thingTypeUID;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@ -63,15 +67,17 @@ public enum GoveeModel {
|
|||||||
public static @Nullable GoveeModel getGoveeModel(BluetoothDiscoveryDevice device) {
|
public static @Nullable GoveeModel getGoveeModel(BluetoothDiscoveryDevice device) {
|
||||||
String name = device.getName();
|
String name = device.getName();
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
if (name.startsWith("Govee") && name.length() >= 11) {
|
if ((name.startsWith("Govee") && name.length() >= 11) || name.startsWith("GVH")) {
|
||||||
String uname = name.toUpperCase();
|
String uname = name.toUpperCase();
|
||||||
for (GoveeModel model : GoveeModel.values()) {
|
for (GoveeModel model : GoveeModel.values()) {
|
||||||
if (uname.contains(model.name())) {
|
if (uname.contains(model.name())) {
|
||||||
|
logger.debug("detected model {}", model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("Device {} is no Govee", name);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,4 +47,13 @@ class GoveeModelTest {
|
|||||||
|
|
||||||
Assertions.assertEquals(GoveeModel.H5074, GoveeModel.getGoveeModel(new BluetoothDiscoveryDevice(mockDevice)));
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user