Skip to content

Commit 9147248

Browse files
authored
Add ability to create Peripheral from ScanResult (#937)
1 parent b6653eb commit 9147248

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

kable-core/api/android/kable-core.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ public final class com/juul/kable/PeripheralBuilder {
337337

338338
public final class com/juul/kable/PeripheralKt {
339339
public static final fun Peripheral (Landroid/bluetooth/BluetoothDevice;Lkotlin/jvm/functions/Function1;)Lcom/juul/kable/Peripheral;
340+
public static final fun Peripheral (Landroid/bluetooth/le/ScanResult;Lkotlin/jvm/functions/Function1;)Lcom/juul/kable/Peripheral;
340341
public static final fun Peripheral (Lcom/juul/kable/Advertisement;Lkotlin/jvm/functions/Function1;)Lcom/juul/kable/Peripheral;
341342
public static final fun Peripheral (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/juul/kable/Peripheral;
342343
public static synthetic fun Peripheral$default (Landroid/bluetooth/BluetoothDevice;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/juul/kable/Peripheral;

kable-core/src/androidMain/kotlin/Peripheral.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.juul.kable
22

33
import android.bluetooth.BluetoothDevice
4+
import android.bluetooth.le.ScanResult
45

56
public actual fun Peripheral(
67
advertisement: Advertisement,
@@ -10,6 +11,12 @@ public actual fun Peripheral(
1011
return Peripheral(advertisement.bluetoothDevice, builderAction)
1112
}
1213

14+
@ExperimentalApi // Experimental while evaluating if this API introduces any footguns.
15+
public fun Peripheral(
16+
scanResult: ScanResult,
17+
builderAction: PeripheralBuilderAction,
18+
): Peripheral = Peripheral(scanResult.device, builderAction)
19+
1320
/** @throws IllegalStateException If bluetooth is not supported. */
1421
public fun Peripheral(
1522
identifier: Identifier,

0 commit comments

Comments
 (0)