@@ -33,6 +33,16 @@ class BLEInterface(MeshInterface):
3333 class BLEError (Exception ):
3434 """An exception class for BLE errors."""
3535
36+ DEVICE_NOT_FOUND = "device_not_found"
37+ MULTIPLE_DEVICES = "multiple_devices"
38+ READ_ERROR = "read_error"
39+ WRITE_ERROR = "write_error"
40+ UNKNOWN = "unknown"
41+
42+ def __init__ (self , message : str , kind : str = UNKNOWN ):
43+ super ().__init__ (message )
44+ self .kind = kind
45+
3646 def __init__ ( # pylint: disable=R0917
3747 self ,
3848 address : Optional [str ],
@@ -157,11 +167,13 @@ def find_device(self, address: Optional[str]) -> BLEDevice:
157167
158168 if len (addressed_devices ) == 0 :
159169 raise BLEInterface .BLEError (
160- f"No Meshtastic BLE peripheral with identifier or address '{ address } ' found. Try --ble-scan to find it."
170+ f"No Meshtastic BLE peripheral with identifier or address '{ address } ' found. Try --ble-scan to find it." ,
171+ BLEInterface .BLEError .DEVICE_NOT_FOUND ,
161172 )
162173 if len (addressed_devices ) > 1 :
163174 raise BLEInterface .BLEError (
164- f"More than one Meshtastic BLE peripheral with identifier or address '{ address } ' found."
175+ f"More than one Meshtastic BLE peripheral with identifier or address '{ address } ' found." ,
176+ BLEInterface .BLEError .MULTIPLE_DEVICES ,
165177 )
166178 return addressed_devices [0 ]
167179
@@ -204,7 +216,10 @@ def _receiveFromRadioImpl(self) -> None:
204216 logger .debug (f"Device disconnected, shutting down { e } " )
205217 self ._want_receive = False
206218 else :
207- raise BLEInterface .BLEError ("Error reading BLE" ) from e
219+ raise BLEInterface .BLEError (
220+ "Error reading BLE" ,
221+ BLEInterface .BLEError .READ_ERROR ,
222+ ) from e
208223 if not b :
209224 if retries < 5 :
210225 time .sleep (0.1 )
@@ -227,7 +242,8 @@ def _sendToRadioImpl(self, toRadio) -> None:
227242 # search Bleak src for org.bluez.Error.InProgress
228243 except Exception as e :
229244 raise BLEInterface .BLEError (
230- "Error writing BLE (are you in the 'bluetooth' user group? did you enter the pairing PIN on your computer?)"
245+ "Error writing BLE (are you in the 'bluetooth' user group? did you enter the pairing PIN on your computer?)" ,
246+ BLEInterface .BLEError .WRITE_ERROR ,
231247 ) from e
232248 # Allow to propagate and then make sure we read
233249 time .sleep (0.01 )
0 commit comments