Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bluetooth.govee] Fix Govee H5102 detection #12373

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}