sok-ble 0.1.8__py3-none-any.whl → 0.1.9a5__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.
@@ -10,6 +10,7 @@ from contextlib import asynccontextmanager
10
10
  from typing import AsyncIterator, Optional
11
11
 
12
12
  import async_timeout
13
+ from bleak.backends.characteristic import BleakGATTCharacteristic
13
14
  from bleak.backends.device import BLEDevice
14
15
  from bleak.exc import BleakError
15
16
 
@@ -86,6 +87,15 @@ class SokBluetoothDevice:
86
87
  self._ble_device.address,
87
88
  err,
88
89
  )
90
+ if client is not None:
91
+ try:
92
+ await asyncio.shield(client.disconnect())
93
+ except (BleakError, asyncio.TimeoutError):
94
+ logger.debug(
95
+ "Failed to disconnect after connect error for %s",
96
+ self._ble_device.address,
97
+ )
98
+ client = None
89
99
  await asyncio.sleep(0.5)
90
100
  else:
91
101
  raise BLEConnectionError(
@@ -114,7 +124,7 @@ class SokBluetoothDevice:
114
124
 
115
125
  queue: asyncio.Queue[bytes] = asyncio.Queue()
116
126
 
117
- def handler(_: int, data: bytearray) -> None:
127
+ def handler(_: BleakGATTCharacteristic, data: bytearray) -> None:
118
128
  queue.put_nowait(bytes(data))
119
129
 
120
130
  await client.start_notify(UUID_RX, handler)
@@ -136,6 +146,10 @@ class SokBluetoothDevice:
136
146
  await asyncio.sleep(0.2)
137
147
  continue
138
148
  raise
149
+ raise BleakError(
150
+ f"Failed to receive response 0x{expected:04X} "
151
+ f"from {self._ble_device.address}"
152
+ )
139
153
 
140
154
  async def async_update(self) -> None:
141
155
  """Poll the device for all telemetry and update attributes."""
@@ -180,13 +194,30 @@ class SokBluetoothDevice:
180
194
  parsed = SokParser.parse_all(responses)
181
195
  logger.debug("Parsed update: %s", parsed)
182
196
 
183
- self.voltage = parsed["voltage"]
184
- self.current = parsed["current"]
185
- self.soc = parsed["soc"]
186
- self.temperature = parsed["temperature"]
187
- self.capacity = parsed["capacity"]
188
- self.num_cycles = parsed["num_cycles"]
189
- self.cell_voltages = parsed["cell_voltages"]
197
+ voltage = parsed.get("voltage")
198
+ self.voltage = voltage if isinstance(voltage, (int, float)) else None
199
+
200
+ current = parsed.get("current")
201
+ self.current = current if isinstance(current, (int, float)) else None
202
+
203
+ soc = parsed.get("soc")
204
+ self.soc = soc if isinstance(soc, int) else None
205
+
206
+ temperature = parsed.get("temperature")
207
+ self.temperature = (
208
+ temperature if isinstance(temperature, (int, float)) else None
209
+ )
210
+
211
+ capacity = parsed.get("capacity")
212
+ self.capacity = capacity if isinstance(capacity, (int, float)) else None
213
+
214
+ num_cycles = parsed.get("num_cycles")
215
+ self.num_cycles = num_cycles if isinstance(num_cycles, int) else None
216
+
217
+ cell_voltages = parsed.get("cell_voltages")
218
+ self.cell_voltages = (
219
+ list(cell_voltages) if isinstance(cell_voltages, list) else None
220
+ )
190
221
 
191
222
  self.num_samples += 1
192
223
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sok-ble
3
- Version: 0.1.8
3
+ Version: 0.1.9a5
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
@@ -13,8 +13,8 @@ Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python :: 3
14
14
  Requires-Python: >=3.11
15
15
  Requires-Dist: async-timeout>=4.0.3
16
- Requires-Dist: bleak-retry-connector>=3.9.0
17
- Requires-Dist: bleak>=0.22.3
16
+ Requires-Dist: bleak-retry-connector>=4.4.3
17
+ Requires-Dist: bleak>=1.0.1
18
18
  Description-Content-Type: text/markdown
19
19
 
20
20
  # SOK BLE
@@ -0,0 +1,9 @@
1
+ sok_ble/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ sok_ble/const.py,sha256=mHtJTbWz_dG3v1lhZrLDzMf-QAG9v5QWlHU9ZKsyYdg,998
3
+ sok_ble/exceptions.py,sha256=_4Fyb-2Ncct2RGjLe1em2M7_e5QcmjVJ92KxtAsbZlk,246
4
+ sok_ble/sok_bluetooth_device.py,sha256=1_EsLxQbvFuqMNd8KuWJpo_2t0m9xKbmGvpdSM2XECQ,9460
5
+ sok_ble/sok_parser.py,sha256=Wcn9oWVrHT1gLU7WB-3rUd2UpVfFwLz_gKQrDYE0H4M,4342
6
+ sok_ble-0.1.9a5.dist-info/METADATA,sha256=1ONNyrSklbq4aOrmqOP2GWtP235FWdRPr6n1jDYj7YM,1592
7
+ sok_ble-0.1.9a5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
8
+ sok_ble-0.1.9a5.dist-info/licenses/LICENSE,sha256=OoKRExpBDDpMbUut-KaARncGL5U8utex4D2ncZVtVF8,11346
9
+ sok_ble-0.1.9a5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,9 +0,0 @@
1
- sok_ble/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- sok_ble/const.py,sha256=mHtJTbWz_dG3v1lhZrLDzMf-QAG9v5QWlHU9ZKsyYdg,998
3
- sok_ble/exceptions.py,sha256=_4Fyb-2Ncct2RGjLe1em2M7_e5QcmjVJ92KxtAsbZlk,246
4
- sok_ble/sok_bluetooth_device.py,sha256=H2FLNtMDe-jfMxao21WAft2myErTnuZvRFsRgB7dqms,8204
5
- sok_ble/sok_parser.py,sha256=Wcn9oWVrHT1gLU7WB-3rUd2UpVfFwLz_gKQrDYE0H4M,4342
6
- sok_ble-0.1.8.dist-info/METADATA,sha256=v-Pzb7-hx_p2rI6Uo8izRQiObH36XdSDkBHbZA8c0OI,1591
7
- sok_ble-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- sok_ble-0.1.8.dist-info/licenses/LICENSE,sha256=OoKRExpBDDpMbUut-KaARncGL5U8utex4D2ncZVtVF8,11346
9
- sok_ble-0.1.8.dist-info/RECORD,,