idotmatrix-api-client 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (63) hide show
  1. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/PKG-INFO +1 -1
  2. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/connection_manager.py +36 -15
  3. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/pyproject.toml +1 -1
  4. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/LICENSE +0 -0
  5. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/README.md +0 -0
  6. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/__init__.py +0 -0
  7. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/apps/__init__.py +0 -0
  8. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/apps/digital_picture_frame.py +0 -0
  9. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/client.py +0 -0
  10. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/const.py +0 -0
  11. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-ErbosDraco1StOpenNbpRegular-l5wX.ttf +0 -0
  12. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-MinecraftStandard.otf +0 -0
  13. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-MinecraftStandardBoldOblique.otf +0 -0
  14. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-PixelOperator8-Bold.ttf +0 -0
  15. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-PixelOperator8.ttf +0 -0
  16. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-PixelifySans-Regular.ttf +0 -0
  17. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-PressStart2P-Regular.ttf +0 -0
  18. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-dogica.ttf +0 -0
  19. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-dogicabold.ttf +0 -0
  20. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-dogicapixel.ttf +0 -0
  21. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16-dogicapixelbold.ttf +0 -0
  22. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16_32-HomeVideo-BLG6G.ttf +0 -0
  23. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16_32-HomeVideoBold-R90Dv.ttf +0 -0
  24. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/16_32-MayfairNbpBold-gAA4.ttf +0 -0
  25. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/32-Jersey10-Regular.ttf +0 -0
  26. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/CC-BY-SA-4.0-License.txt +0 -0
  27. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/ErbosDraco-License.txt +0 -0
  28. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/HomeVideo-License.txt +0 -0
  29. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/Jersey10-Regular-License.txt +0 -0
  30. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/MayfairNbpBold-License.txt +0 -0
  31. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/MinecraftStandard-License.txt +0 -0
  32. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/PixelOperator-License.txt +0 -0
  33. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/PixelifySans-License.txt +0 -0
  34. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/PressStart2P-Regular-License.txt +0 -0
  35. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/Rain-DRM3-License.txt +0 -0
  36. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/Rain-DRM3.otf +0 -0
  37. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/fonts/dogica_license.txt +0 -0
  38. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/__init__.py +0 -0
  39. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/chronograph.py +0 -0
  40. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/clock.py +0 -0
  41. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/common.py +0 -0
  42. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/countdown.py +0 -0
  43. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/eco.py +0 -0
  44. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/effect.py +0 -0
  45. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/fullscreen_color.py +0 -0
  46. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/gif.py +0 -0
  47. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/graffiti.py +0 -0
  48. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/image.py +0 -0
  49. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/music_sync.py +0 -0
  50. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/scoreboard.py +0 -0
  51. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/system.py +0 -0
  52. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/modules/text.py +0 -0
  53. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/protocol.py +0 -0
  54. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/screensize.py +0 -0
  55. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/transport.py +0 -0
  56. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/__init__.py +0 -0
  57. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/color_utils.py +0 -0
  58. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/command_ack.py +0 -0
  59. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/device_info.py +0 -0
  60. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/device_material.py +0 -0
  61. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/file_watch.py +0 -0
  62. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/image_utils.py +0 -0
  63. {idotmatrix_api_client-0.2.0 → idotmatrix_api_client-0.2.2}/idotmatrix/util/upload_ack.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: idotmatrix-api-client
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A library for controlling iDotMatrix displays.
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE
@@ -35,6 +35,9 @@ class ConnectionListener:
35
35
  # the official app gives up on an upload if the device does not acknowledge a chunk within 5 seconds
36
36
  UPLOAD_ACK_TIMEOUT_SECONDS = 5
37
37
 
38
+ # the official app writes the BLE packets of an upload chunk 20 ms apart, the device may lose data that arrives faster
39
+ UPLOAD_WRITE_INTERVAL_SECONDS = 0.02
40
+
38
41
  # the device answers normal commands within a few milliseconds
39
42
  COMMAND_ACK_TIMEOUT_SECONDS = 1
40
43
 
@@ -146,15 +149,16 @@ class ConnectionManager:
146
149
  """
147
150
  Sets the device to connect to as a `BLEDevice`, f.e. one that a scanner of Home Assistant found, which knows
148
151
  how to reach the device (f.e. over a Bluetooth proxy). Call it again with the newer `BLEDevice` when the
149
- scanner found the device again. An established connection is not interrupted, the new device is used for
150
- the next connection.
152
+ scanner found the device again (which happens all the time). The transport is never replaced for the same
153
+ device here, so a connection or a connection attempt is not disturbed, the new device is used for the next
154
+ connection.
151
155
  Args:
152
156
  device (BLEDevice): The iDotMatrix device.
153
157
  """
154
158
  same_device = self.address == device.address
155
159
  self.address = device.address
156
160
  self._transport_target = device
157
- if not (same_device and self.is_connected()):
161
+ if self._transport is None or not same_device:
158
162
  self._create_transport()
159
163
 
160
164
  def _create_transport(self) -> Transport:
@@ -230,15 +234,16 @@ class ConnectionManager:
230
234
 
231
235
  if not self.is_connected():
232
236
  self.logging.info(f"connecting to {self.address}...")
233
- self._create_transport() # a newer device may have been set while connected
234
- await self._transport.connect()
237
+ # a newer device may have been set since the last connection
238
+ transport = self._create_transport()
239
+ await transport.connect()
235
240
  self._connected = True
236
241
  newly_connected = True
237
242
  # the negotiated MTU can differ between connections, so it has to be detected again
238
243
  self._ble_packet_size = None
239
244
  self.logging.info(f"connected to {self.address}")
240
245
  self._last_activity = time.monotonic()
241
- await self._subscribe_to_notifications()
246
+ await self._subscribe_to_notifications(transport)
242
247
  self._update_heartbeat()
243
248
  else:
244
249
  self.logging.info(f"already connected to {self.address}")
@@ -378,13 +383,13 @@ class ConnectionManager:
378
383
  f"the device rejected the command {command.hex()} (notification {notification.hex()})")
379
384
  return True
380
385
 
381
- async def _subscribe_to_notifications(self) -> None:
386
+ async def _subscribe_to_notifications(self, transport: Transport) -> None:
382
387
  """
383
388
  Subscribes to the notifications of the device, which acknowledge the chunks of an upload.
384
389
  """
385
390
  self._notifications = asyncio.Queue()
386
391
  try:
387
- await self._transport.start_notify(self._on_notification)
392
+ await transport.start_notify(self._on_notification)
388
393
  self._notifications_available = True
389
394
  except Exception as e:
390
395
  self._notifications_available = False
@@ -395,14 +400,17 @@ class ConnectionManager:
395
400
  self._last_activity = time.monotonic()
396
401
  self._notifications.put_nowait(bytes(data))
397
402
 
398
- async def _wait_for_upload_status(self) -> UploadStatus:
403
+ async def _wait_for_upload_status(self, deadline: float) -> UploadStatus:
399
404
  """
400
405
  Waits for the device to acknowledge an upload chunk.
406
+ Args:
407
+ deadline: The loop time at which the wait ends. Like in the official app it is counted from the start of
408
+ the chunk, not from its last write.
401
409
  Raises:
402
410
  UploadError: If the device rejects the upload or does not answer in time.
403
411
  """
404
412
  try:
405
- async with asyncio.timeout(UPLOAD_ACK_TIMEOUT_SECONDS):
413
+ async with asyncio.timeout_at(deadline):
406
414
  while True:
407
415
  notification = await self._notifications.get()
408
416
  status = parse_upload_notification(notification)
@@ -466,17 +474,30 @@ class ConnectionManager:
466
474
  self._notifications = asyncio.Queue()
467
475
 
468
476
  for i, packet in enumerate(packets):
469
- for j, ble_paket in enumerate(packet):
470
- self.logging.debug(f"sending packet {i + 1}.{j + 1} of {len(packets)}.{len(packets[-1])}")
471
- wait_for_response = response if j == len(packet) - 1 else False
472
- await self._transport.write(ble_paket, response=wait_for_response)
477
+ deadline = asyncio.get_running_loop().time() + UPLOAD_ACK_TIMEOUT_SECONDS
478
+ await self._write_chunk(packet, response, paced=wait_for_ack, label=f"{i + 1} of {len(packets)}")
473
479
  if wait_for_ack:
474
- status = await self._wait_for_upload_status()
480
+ status = await self._wait_for_upload_status(deadline)
475
481
  if status == UploadStatus.FINISHED and i < len(packets) - 1:
476
482
  # f.e. the device already has the same data stored
477
483
  self.logging.debug("the device reports the upload as finished, skipping the remaining packets")
478
484
  return
479
485
 
486
+ async def _write_chunk(self, packet: List[bytearray | bytes], response: bool, paced: bool, label: str):
487
+ """
488
+ Writes the BLE packets of one packet. Only the last one is written with a response, if requested.
489
+ Args:
490
+ packet: The BLE packets to write.
491
+ response: If True, the last BLE packet is written with response.
492
+ paced: If True, the writes are spaced `UPLOAD_WRITE_INTERVAL_SECONDS` apart.
493
+ label: Describes the packet in the log.
494
+ """
495
+ for j, ble_packet in enumerate(packet):
496
+ if paced and j > 0:
497
+ await asyncio.sleep(UPLOAD_WRITE_INTERVAL_SECONDS)
498
+ self.logging.debug(f"sending packet {label}.{j + 1} of {len(packet)}")
499
+ await self._transport.write(ble_packet, response=response if j == len(packet) - 1 else False)
500
+
480
501
  @staticmethod
481
502
  def _split_oversized_ble_packets(
482
503
  packets: List[List[bytearray | bytes]],
@@ -4,7 +4,7 @@ description = "A library for controlling iDotMatrix displays."
4
4
  license = "GPL-3.0-or-later"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12,<3.15"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  classifiers = [
9
9
  "Intended Audience :: Developers",
10
10
  ]