7
7
import json
8
8
9
9
from .core import log_info , log_warn , ble , register_irq_handler
10
- from .device import DeviceConnection
10
+ from .device import DeviceConnection , Device
11
11
12
12
_IRQ_ENCRYPTION_UPDATE = const (28 )
13
13
_IRQ_GET_SECRET = const (29 )
@@ -72,6 +72,15 @@ def _save_secrets(arg=None):
72
72
_modified = False
73
73
74
74
75
+ def _get_connection (key ) -> DeviceConnection :
76
+ if not key :
77
+ return None
78
+ addr = bytes (reversed (key [- 6 :]))
79
+ for connection in DeviceConnection ._connected .values ():
80
+ if connection .device .addr == addr :
81
+ return connection
82
+
83
+
75
84
def _security_irq (event , data ):
76
85
global _modified
77
86
@@ -84,6 +93,7 @@ def _security_irq(event, data):
84
93
connection .authenticated = authenticated
85
94
connection .bonded = bonded
86
95
connection .key_size = key_size
96
+ connection .pairing_in_progress = False
87
97
# TODO: Handle failure.
88
98
if encrypted and connection ._pair_event :
89
99
connection ._pair_event .set ()
@@ -128,6 +138,11 @@ def _security_irq(event, data):
128
138
else :
129
139
# Return the secret for this key (or None).
130
140
key = sec_type , bytes (key )
141
+
142
+ if conn := _get_connection (key ):
143
+ log_info ("encryption / pairing started" , conn )
144
+ conn .pairing_in_progress = True
145
+
131
146
return _secrets .get (key , None )
132
147
133
148
elif event == _IRQ_PASSKEY_ACTION :
0 commit comments