Sony headphones: Fix recognition of some bluetooth names

This commit is contained in:
José Rebelo
2025-09-02 19:40:03 +01:00
parent 243ef19606
commit 24c96a6497
4 changed files with 24 additions and 9 deletions
@@ -29,7 +29,7 @@ public class SonyWFC510Coordinator extends SonyHeadphonesCoordinator {
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile("WF-C510");
return Pattern.compile(".*WF-C510.*");
}
@Override
@@ -29,7 +29,7 @@ public class SonyWFC700NCoordinator extends SonyHeadphonesCoordinator {
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile("WF-C700N");
return Pattern.compile(".*WF-C700N.*");
}
@Override
@@ -29,7 +29,8 @@ public class SonyWFC710NCoordinator extends SonyHeadphonesCoordinator {
@Override
protected Pattern getSupportedDeviceName() {
return Pattern.compile("WF-C710N");
// Each headphone reports a separate LE_WF-C710N, which we must ignore
return Pattern.compile("(?!LE_).*WF-C710N$");
}
@Override
@@ -46,29 +46,43 @@ public class AbstractDeviceCoordinatorTest extends TestBase {
put("Amazfit T-Rex 3", DeviceType.AMAZFITTREX3);
put("Amazfit T-Rex Ultra", DeviceType.AMAZFITTREXULTRA);
put("Xiaomi Smart Band 7", DeviceType.MIBAND7);
put("Xiaomi Band 9 Active AB01", DeviceType.MIBAND9ACTIVE);
put("P8", DeviceType.WASPOS);
put("P8DFU", DeviceType.WASPOS);
put("P80", DeviceType.COLMI_P80);
put("R11C_B200", DeviceType.YAWELL_R11);
put("R11_B200", DeviceType.YAWELL_R11);
put("WF-C710N", DeviceType.SONY_WF_C710N);
put("John's WF-C710N", DeviceType.SONY_WF_C710N);
put("LE_WF-C710N", null);
}};
for (Map.Entry<String, DeviceType> e : bluetoothNameToExpectedType.entrySet()) {
final String bluetoothName = e.getKey();
final DeviceType expectedType = e.getValue();
final List<DeviceType> matches = new ArrayList<>(1);
// Check the bluetooth name against all existing coordinators
for (DeviceType type : DeviceType.values()) {
final Pattern pattern = ((AbstractDeviceCoordinator) type.getDeviceCoordinator()).getSupportedDeviceName();
if (pattern != null) {
if (pattern.matcher(e.getKey()).matches()) {
if (pattern.matcher(bluetoothName).matches()) {
matches.add(type);
}
}
}
Assert.assertEquals(
"Bluetooth name " + e.getKey() + " should only match the expected DeviceType",
Collections.singletonList(e.getValue()),
matches
);
if (expectedType != null) {
Assert.assertEquals(
"Bluetooth name " + bluetoothName + " should only match the expected DeviceType",
Collections.singletonList(expectedType),
matches
);
} else {
Assert.assertTrue(
"Bluetooth name " + bluetoothName + " should match no DeviceType",
matches.isEmpty()
);
}
}
}
}