sok-ble 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ try:
26
26
  )
27
27
  except Exception: # pragma: no cover - optional dependency
28
28
  from bleak import BleakClient as BleakClientWithServiceCache
29
+
29
30
  establish_connection = None # type: ignore[misc]
30
31
 
31
32
 
@@ -54,6 +55,8 @@ class SokBluetoothDevice:
54
55
  """Connect to the device and yield a BLE client."""
55
56
  logger.debug("Connecting to %s", self._ble_device.address)
56
57
  last_err: Exception | None = None
58
+ client: BleakClientWithServiceCache | None = None
59
+
57
60
  for attempt in range(3):
58
61
  try:
59
62
  if establish_connection:
@@ -65,7 +68,8 @@ class SokBluetoothDevice:
65
68
  )
66
69
  else:
67
70
  client = BleakClientWithServiceCache(
68
- self._ble_device, adapter=self._adapter
71
+ self._ble_device,
72
+ adapter=self._adapter,
69
73
  )
70
74
  await client.connect()
71
75
 
@@ -73,15 +77,7 @@ class SokBluetoothDevice:
73
77
  async with async_timeout.timeout(5):
74
78
  _ = client.services
75
79
  await asyncio.sleep(0.15)
76
-
77
- try:
78
- yield client
79
- finally:
80
- await client.disconnect()
81
- logger.debug(
82
- "Disconnected from %s", self._ble_device.address
83
- )
84
- return
80
+ break
85
81
  except (BleakError, asyncio.TimeoutError) as err:
86
82
  last_err = err
87
83
  logger.debug(
@@ -91,10 +87,17 @@ class SokBluetoothDevice:
91
87
  err,
92
88
  )
93
89
  await asyncio.sleep(0.5)
94
-
95
- raise BLEConnectionError(
96
- f"Unable to establish GATT connection to {self._ble_device.address}"
97
- ) from last_err
90
+ else:
91
+ raise BLEConnectionError(
92
+ f"Unable to establish GATT connection to {self._ble_device.address}"
93
+ ) from last_err
94
+
95
+ assert client is not None
96
+ try:
97
+ yield client
98
+ finally:
99
+ await client.disconnect()
100
+ logger.debug("Disconnected from %s", self._ble_device.address)
98
101
 
99
102
  async def _send_command(
100
103
  self, client: BleakClientWithServiceCache, cmd: int, expected: int
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sok-ble
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: SOK BLE battery interface library
5
5
  Project-URL: Homepage, https://github.com/IAmTheMitchell/sok-ble
6
6
  Project-URL: Bug Tracker, https://github.com/IAmTheMitchell/sok-ble/issues
@@ -1,9 +1,9 @@
1
1
  sok_ble/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sok_ble/const.py,sha256=mHtJTbWz_dG3v1lhZrLDzMf-QAG9v5QWlHU9ZKsyYdg,998
3
3
  sok_ble/exceptions.py,sha256=7H1yUqqnrKyi3LwxRCMF7RkuGp_rgdy9j35nrMOgz44,247
4
- sok_ble/sok_bluetooth_device.py,sha256=agF3lfbkCiMRNrsa3MW7lAEC2njEguum0NnbhdhWntk,8143
4
+ sok_ble/sok_bluetooth_device.py,sha256=Mu-DW15qwl5EKXL84Wi1KHEWFUZ-cHiTPNgz3hwNTfk,8200
5
5
  sok_ble/sok_parser.py,sha256=8yug65x3RdkLKbYlP-fEWiysaHByyenKV_gAzhIKeU0,4337
6
- sok_ble-0.1.5.dist-info/METADATA,sha256=t8cQVUp3wTjxOpZfLH2VQTx-inVP0YYdJgXKc0utC9U,1490
7
- sok_ble-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- sok_ble-0.1.5.dist-info/licenses/LICENSE,sha256=OoKRExpBDDpMbUut-KaARncGL5U8utex4D2ncZVtVF8,11346
9
- sok_ble-0.1.5.dist-info/RECORD,,
6
+ sok_ble-0.1.6.dist-info/METADATA,sha256=QQu2sGiAFSZ2jMVWot8fm96KK1yRcxcDVusQh2TdGsQ,1490
7
+ sok_ble-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ sok_ble-0.1.6.dist-info/licenses/LICENSE,sha256=OoKRExpBDDpMbUut-KaARncGL5U8utex4D2ncZVtVF8,11346
9
+ sok_ble-0.1.6.dist-info/RECORD,,