meshcore 2.1.13__py3-none-any.whl → 2.1.15__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.

Potentially problematic release.


This version of meshcore might be problematic. Click here for more details.

@@ -1,7 +1,8 @@
1
1
  import logging
2
+ import asyncio
2
3
  from typing import Optional
3
4
 
4
- from ..events import Event, EventType
5
+ from ..events import Event, EventDispatcher, EventType
5
6
  from .base import CommandHandlerBase, DestinationType, _validate_destination
6
7
 
7
8
  logger = logging.getLogger("meshcore")
@@ -17,26 +18,70 @@ class ContactCommands(CommandHandlerBase):
17
18
  print("Fetching contacts ", end="", flush=True)
18
19
  # wait first event
19
20
  res = await self.send(data)
20
- while True:
21
- # wait next event
22
- res = await self.wait_for_events(
23
- [EventType.NEXT_CONTACT, EventType.CONTACTS, EventType.ERROR],
24
- timeout=5)
25
- if res is None: # Timeout
26
- if anim:
21
+ timeout = 5
22
+ contact_nb = 0
23
+ # Inline wait for events to continue waiting for CONTACTS event
24
+ # while receiving NEXT_CONTACTs (or it might be missed over serial)
25
+ try:
26
+ # Create futures for all expected events
27
+ futures = []
28
+ for event_type in [EventType.ERROR, EventType.NEXT_CONTACT, EventType.CONTACTS] :
29
+ future = asyncio.create_task(
30
+ self.dispatcher.wait_for_event(event_type, {}, timeout=timeout)
31
+ )
32
+ futures.append(future)
33
+
34
+ while True:
35
+
36
+ # Wait for the first event to complete or all to timeout
37
+ done, pending = await asyncio.wait(
38
+ futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
39
+ )
40
+
41
+ # Check if any future completed successfully
42
+ if len(done) == 0:
27
43
  print(" Timeout")
28
- return res
29
- if res.type == EventType.ERROR:
30
- if anim:
31
- print(" Error")
32
- return res
33
- elif res.type == EventType.CONTACTS:
34
- if anim:
35
- print(" Done")
36
- return res
37
- elif res.type == EventType.NEXT_CONTACT:
38
- if anim:
39
- print(".", end="", flush=True)
44
+ for future in pending: # cancel all futures
45
+ future.cancel()
46
+ return None
47
+
48
+ for future in done:
49
+ event = await future
50
+
51
+ if event:
52
+ if event.type == EventType.NEXT_CONTACT:
53
+ if anim:
54
+ contact_nb = contact_nb+1
55
+ print(".", end="", flush=True)
56
+ else: # Done or Error ... cancel pending and return
57
+ if anim:
58
+ if event.type == EventType.CONTACTS:
59
+ print ((len(event.payload)-contact_nb)*"." + " Done")
60
+ else :
61
+ print(" Error")
62
+ for future in pending:
63
+ future.cancel()
64
+ return event
65
+
66
+ futures = []
67
+ for future in pending: # put back pending
68
+ futures.append(future)
69
+
70
+ future = asyncio.create_task( # and recreate NEXT_CONTACT
71
+ self.dispatcher.wait_for_event(EventType.NEXT_CONTACT, {}, timeout)
72
+ )
73
+ futures.append(future)
74
+
75
+ except asyncio.TimeoutError:
76
+ logger.debug(f"Timeout receiving contacts")
77
+ if anim:
78
+ print(" Timeout")
79
+ return None
80
+ except Exception as e:
81
+ logger.debug(f"Command error: {e}")
82
+ if anim:
83
+ print(" Error")
84
+ return Event(EventType.ERROR, {"error": str(e)})
40
85
 
41
86
  async def reset_path(self, key: DestinationType) -> Event:
42
87
  key_bytes = _validate_destination(key, prefix_length=32)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshcore
3
- Version: 2.1.13
3
+ Version: 2.1.15
4
4
  Summary: Base classes for communicating with meshcore companion radios
5
5
  Project-URL: Homepage, https://github.com/fdlamotte/meshcore_py
6
6
  Project-URL: Issues, https://github.com/fdlamotte/meshcore_py/issues
@@ -12,10 +12,10 @@ meshcore/tcp_cx.py,sha256=05YRVMnjY5aVBTJcHa0uG4VfFKGbV6hQ1pPIsJg4CDI,4227
12
12
  meshcore/commands/__init__.py,sha256=NNmkTEcL-DLyuwKLUagEzpqe3C6ui2tETbu_mUd4p-I,441
13
13
  meshcore/commands/base.py,sha256=0bDHcNGlKoej03xJqzo_wL5ctoPQU5kcK1Ca5sZh1pk,7097
14
14
  meshcore/commands/binary.py,sha256=MVKXrT4pFSlzFkVFLBX988Eh57tRwunw4XPKBumbQNU,4890
15
- meshcore/commands/contact.py,sha256=D9aciwSmpWsbyY64bsNkI_bx8-utUgjjzbRHVLjv9ZE,4553
15
+ meshcore/commands/contact.py,sha256=MZ-MqUElkPhpnbMtVW-8MZoopPjjZxI05WvzOv3dB6E,6516
16
16
  meshcore/commands/device.py,sha256=vstyy1crvhGbDgCAtyCWyjj3X8F2CpMw1LFTOwoHh6M,8273
17
17
  meshcore/commands/messaging.py,sha256=MIVGM5G8J16qimKjCHdrlEiVJ4g_MsBaZKPvRJHJcLU,8306
18
- meshcore-2.1.13.dist-info/METADATA,sha256=-4t1wQS5utb38xkQkJw-n0rOX_wLyY1oaPGUeWBD3ps,25317
19
- meshcore-2.1.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
- meshcore-2.1.13.dist-info/licenses/LICENSE,sha256=o62-JWT_C-ZqEtzb1Gl_PPtPr0pVT8KDmgji_Y_bejI,1075
21
- meshcore-2.1.13.dist-info/RECORD,,
18
+ meshcore-2.1.15.dist-info/METADATA,sha256=BvGIAxqFglY72AXQRd4X2uuzpZrKsKeXvM3T0RH-MGc,25317
19
+ meshcore-2.1.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
+ meshcore-2.1.15.dist-info/licenses/LICENSE,sha256=o62-JWT_C-ZqEtzb1Gl_PPtPr0pVT8KDmgji_Y_bejI,1075
21
+ meshcore-2.1.15.dist-info/RECORD,,