From 27bccd378e86b1e180af33b761f918eba780e12c Mon Sep 17 00:00:00 2001 From: Mateo Gianolio Date: Tue, 2 Jan 2024 09:48:39 +0100 Subject: [PATCH] fix(#35): apply patch from issue to fix scanWifiList issue --- .../EspIdfProvisioningModule.kt | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt b/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt index 50cf284..f40affa 100644 --- a/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt +++ b/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt @@ -212,42 +212,31 @@ class EspIdfProvisioningModule internal constructor(context: ReactApplicationCon else -> ESPConstants.SecurityType.SECURITY_2 } + // If no ESP device found in list (no scan has been performed), create a new one + val espDevice: ESPDevice; if (espDevices[deviceName] != null) { - val result = Arguments.createMap() - result.putString("name", espDevices[deviceName]?.deviceName) - result.putArray("capabilities", Arguments.fromList(espDevices[deviceName]?.deviceCapabilities)) - result.putInt("security", security) - result.putString("transport", transport) - result.putString("username", espDevices[deviceName]?.userName) - result.putString("versionInfo", espDevices[deviceName]?.versionInfo) - - promise?.resolve(result) - return + espDevice = espDevices[deviceName]!! + } else { + espDevice = espProvisionManager.createESPDevice(transportEnum, securityEnum) + espDevice.deviceName = deviceName + espDevices[deviceName] = espDevice } - - // If no ESP device found in list (no scan has been performed), create a new one - val espDevice = espProvisionManager.createESPDevice(transportEnum, securityEnum) - var bleDevice = espDevice?.bluetoothDevice - + // bluetoothDevice, deviceName and primaryServiceUuid were filled at onPeripheralFound // If the bluetooth device does not contain service uuids, try using the bonded // one (if it exists) - if (bleDevice?.uuids == null) { - bleDevice = bluetoothAdapter.bondedDevices.find { - bondedDevice -> bondedDevice.name == deviceName + if (espDevice.bluetoothDevice == null) { + espDevice.bluetoothDevice = bluetoothAdapter.bondedDevices.find { + bondedDevice -> bondedDevice.name == deviceName } } // If the bluetooth device exists and contains service uuids, we will be able to connect to it - if (bleDevice?.uuids != null) { - espDevice.bluetoothDevice = bleDevice - espDevice.deviceName = deviceName + if (espDevice.bluetoothDevice != null) { espDevice.proofOfPossession = proofOfPossession if (username != null) { espDevice.userName = username } - espDevices[deviceName] = espDevice - val result = Arguments.createMap() result.putString("name", espDevice.deviceName) result.putArray("capabilities", Arguments.fromList(espDevice.deviceCapabilities))