Skip to content

Commit ac0904e

Browse files
committed
improve _bleio.Connection.bind() doc, validation, and error messages
1 parent 57fa43a commit ac0904e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ msgstr ""
268268
msgid "%q, %q, and %q must all be the same length"
269269
msgstr ""
270270

271-
#: py/objint.c shared-bindings/storage/__init__.c
271+
#: py/objint.c shared-bindings/_bleio/Connection.c
272+
#: shared-bindings/storage/__init__.c
272273
msgid "%q=%q"
273274
msgstr ""
274275

@@ -550,6 +551,10 @@ msgstr ""
550551
msgid "Already have all-matches listener"
551552
msgstr ""
552553

554+
#: ports/espressif/common-hal/_bleio/__init__.c
555+
msgid "Already in progress"
556+
msgstr ""
557+
553558
#: ports/espressif/bindings/espnow/ESPNow.c
554559
#: ports/espressif/common-hal/espulp/ULP.c
555560
#: shared-module/memorymonitor/AllocationAlarm.c
@@ -3173,10 +3178,6 @@ msgstr ""
31733178
msgid "indices must be integers, slices, or Boolean lists"
31743179
msgstr ""
31753180

3176-
#: ports/espressif/common-hal/busio/I2C.c
3177-
msgid "init I2C"
3178-
msgstr ""
3179-
31803181
#: extmod/ulab/code/scipy/optimize/optimize.c
31813182
msgid "initial values must be iterable"
31823183
msgstr ""

ports/espressif/common-hal/_bleio/__init__.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ void check_nimble_error(int rc, const char *file, size_t line) {
103103
case BLE_HS_ENOTCONN:
104104
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
105105
return;
106+
case BLE_HS_EALREADY:
107+
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Already in progress"));
108+
return;
106109
default:
107110
#if CIRCUITPY_VERBOSE_BLE || CIRCUITPY_DEBUG
108111
if (file) {

ports/nordic/common-hal/_bleio/__init__.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void check_nrf_error(uint32_t err_code) {
3535
case NRF_ERROR_INVALID_PARAM:
3636
mp_raise_ValueError(MP_ERROR_TEXT("Invalid BLE parameter"));
3737
return;
38+
case NRF_ERROR_INVALID_STATE:
39+
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Invalid state"));
40+
return;
3841
case BLE_ERROR_INVALID_CONN_HANDLE:
3942
mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected"));
4043
return;

shared-bindings/_bleio/Connection.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connecti
6666

6767

6868
//| def pair(self, *, bond: bool = True) -> None:
69-
//| """Pair to the peer to improve security."""
69+
//| """Pair to the peer to improve security.
70+
//|
71+
//| **Limitation**: Currently ``bond``must be ``True``: bonding always occurs.
72+
//| """
7073
//| ...
7174
static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
7275
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@@ -79,6 +82,9 @@ static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args
7982
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
8083
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
8184

85+
if (args[ARG_bond].u_bool == false) {
86+
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q=%q"), MP_QSTR_bond, MP_QSTR_False);
87+
}
8288
bleio_connection_ensure_connected(self);
8389

8490
common_hal_bleio_connection_pair(self->connection, args[ARG_bond].u_bool);

0 commit comments

Comments
 (0)