From b2cf36ebfa7c6adbe34adc29b71235feeb8e24fd Mon Sep 17 00:00:00 2001 From: oliexdev Date: Wed, 3 Sep 2025 16:41:08 +0200 Subject: [PATCH] Improve detection logic for QN and Renpho scales The device discovery for QN and Renpho scales has been refined. The QN scale detection now explicitly checks for specific QN service UUIDs (0xFFE0 or 0xFFF0) in addition to the device name starting with "QN-Scale". The Renpho scale detection now ensures the device has standard weight service UUIDs (0x181D or 0x181B) and its name contains "renpho-scale", while also excluding devices that appear to be QN scales (i.e., devices with QN-specific UUIDs). --- .../core/bluetooth/modern/QNHandler.kt | 25 ++++++++++--------- .../core/bluetooth/modern/RenphoHandler.kt | 17 ++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/QNHandler.kt b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/QNHandler.kt index e744a541..2a88b514 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/QNHandler.kt +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/QNHandler.kt @@ -17,6 +17,7 @@ */ package com.health.openscale.core.bluetooth.modern +import android.R.attr.name import com.health.openscale.R import com.health.openscale.core.bluetooth.data.ScaleMeasurement import com.health.openscale.core.bluetooth.data.ScaleUser @@ -73,24 +74,24 @@ class QNHandler : ScaleDeviceHandler() { // ---- Capability discovery -------------------------------------------------- override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? { - val uuids = device.serviceUuids + val uuids = device.serviceUuids.toSet() - val supports = device.name.startsWith("QN-Scale") && uuids.any { it == SVC_T1 || it == SVC_T2 } - if (!supports) return null + val hasQN = uuids.contains(uuid16(0xFFE0)) || uuids.contains(uuid16(0xFFF0)) - // Remember a hint about which flavor we likely have - likelyUseType1 = uuids.contains(SVC_T1) && !uuids.contains(SVC_T2) + if (!hasQN) return null + if (!device.name.startsWith("QN-Scale")) return null - val capabilities = buildSet { - add(DeviceCapability.TIME_SYNC) - add(DeviceCapability.LIVE_WEIGHT_STREAM) - add(DeviceCapability.BODY_COMPOSITION) // derived via impedance - } + likelyUseType1 = uuids.contains(uuid16(0xFFE0)) && !uuids.contains(uuid16(0xFFF0)) + val caps = setOf( + DeviceCapability.TIME_SYNC, + DeviceCapability.LIVE_WEIGHT_STREAM, + DeviceCapability.BODY_COMPOSITION + ) return DeviceSupport( displayName = "QN Scale", - capabilities = capabilities, - implemented = capabilities, + capabilities = caps, + implemented = caps, linkMode = LinkMode.CONNECT_GATT ) } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/RenphoHandler.kt b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/RenphoHandler.kt index 5fcf7178..2287f2ca 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/RenphoHandler.kt +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/modern/RenphoHandler.kt @@ -96,13 +96,14 @@ class RenphoHandler : ScaleDeviceHandler() { * We keep this moderately strict to avoid grabbing unrelated scales. */ override fun supportFor(device: ScannedDeviceInfo): DeviceSupport? { - val name = device.name.lowercase(Locale.ROOT) + val nameLc = device.name.lowercase() val svc = device.serviceUuids.toSet() - val looksRenpho = - name.contains("Renpho-Scale".lowercase()) || - (svc.contains(SERV_WEIGHT_SCALE) && svc.contains(SERV_BODY_COMP)) + val hasStdWeight = svc.contains(uuid16(0x181D)) || svc.contains(uuid16(0x181B)) + val hasQN = svc.contains(uuid16(0xFFE0)) || svc.contains(uuid16(0xFFF0)) + val looksRenphoByName = nameLc.contains("renpho-scale") + val looksRenpho = (hasStdWeight && looksRenphoByName) && !hasQN if (!looksRenpho) return null val caps = setOf( @@ -110,17 +111,15 @@ class RenphoHandler : ScaleDeviceHandler() { DeviceCapability.USER_SYNC, DeviceCapability.BODY_COMPOSITION ) - val impl = setOf( DeviceCapability.TIME_SYNC, - DeviceCapability.USER_SYNC, + DeviceCapability.USER_SYNC ) - return DeviceSupport( displayName = "RENPHO ES-WBE28", capabilities = caps, - implemented = impl, - linkMode = LinkMode.CONNECT_GATT + implemented = impl, + linkMode = LinkMode.CONNECT_GATT ) }