meshcore-cli 1.6.8__tar.gz → 1.6.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: meshcore-cli
3
- Version: 1.6.8
3
+ Version: 1.6.9
4
4
  Summary: Command line interface to meshcore companion radios and repeaters
5
5
  Project-URL: Homepage, https://github.com/fdlamotte/meshcore-cli
6
6
  Project-URL: Issues, https://github.com/fdlamotte/meshcore-cli/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meshcore-cli"
7
- version = "1.6.8"
7
+ version = "1.6.9"
8
8
  authors = [
9
9
  { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
10
10
  ]
@@ -35,7 +35,7 @@ except ImportError:
35
35
  from meshcore import MeshCore, EventType, logger
36
36
 
37
37
  # Version
38
- VERSION = "v1.6.8"
38
+ VERSION = "v1.6.9"
39
39
 
40
40
  # default ble address is stored in a config file
41
41
  MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
@@ -2238,62 +2238,57 @@ async def get_channel_by_name (mc, name):
2238
2238
 
2239
2239
  return None
2240
2240
 
2241
- async def get_contacts (mc, anim=False, lastomod=0, timeout=5) :
2241
+ async def get_contacts(mc, anim=False, lastomod=0, timeout=5):
2242
2242
  if mc._contacts:
2243
2243
  return
2244
2244
 
2245
2245
  if anim:
2246
2246
  print("Fetching contacts ", end="", flush=True)
2247
2247
 
2248
- await mc.commands.get_contacts_async()
2248
+ loop = asyncio.get_running_loop()
2249
+ result = loop.create_future()
2250
+ state = {"n": 0, "activity": False}
2249
2251
 
2250
- futures = []
2251
- contact_nb = 0
2252
- for event_type in [EventType.ERROR, EventType.NEXT_CONTACT, EventType.CONTACTS] :
2253
- future = asyncio.create_task(
2254
- mc.wait_for_event(event_type, {}, timeout=timeout)
2255
- )
2256
- futures.append(future)
2252
+ def on_next(event):
2253
+ state["n"] += 1
2254
+ state["activity"] = True
2255
+ if anim:
2256
+ print(".", end="", flush=True)
2257
2257
 
2258
- while True:
2259
- # Wait for the first event to complete or all to timeout
2260
- done, pending = await asyncio.wait(
2261
- futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
2262
- )
2258
+ def on_end(event):
2259
+ logger.debug(f"get_contacts: got {event.type}")
2260
+ if not result.done():
2261
+ result.set_result(event)
2263
2262
 
2264
- # Check if any future completed successfully
2265
- if len(done) == 0:
2266
- logger.debug("Timeout while getting contacts")
2267
- for future in pending: # cancel all futures
2268
- future.cancel()
2269
- return None
2270
-
2271
- for future in done:
2272
- event = await future
2273
-
2274
- if event:
2275
- if event.type == EventType.NEXT_CONTACT:
2276
- if anim:
2277
- contact_nb = contact_nb+1
2278
- print(".", end="", flush=True)
2279
- else: # Done or Error ... cancel pending and return
2280
- if anim:
2281
- if event.type == EventType.CONTACTS:
2282
- print ((len(event.payload)-contact_nb)*"." + " Done")
2283
- else :
2284
- print(" Error")
2285
- for future in pending:
2286
- future.cancel()
2287
- return event
2288
-
2289
- futures = []
2290
- for future in pending: # put back pending
2291
- futures.append(future)
2292
-
2293
- future = asyncio.create_task( # and recreate NEXT_CONTACT
2294
- mc.wait_for_event(EventType.NEXT_CONTACT, {}, timeout)
2295
- )
2296
- futures.append(future)
2263
+ subs = [
2264
+ mc.subscribe(EventType.NEXT_CONTACT, on_next),
2265
+ mc.subscribe(EventType.CONTACTS, on_end),
2266
+ mc.subscribe(EventType.ERROR, on_end),
2267
+ ]
2268
+
2269
+ try:
2270
+ await mc.commands.get_contacts_async()
2271
+
2272
+ while True:
2273
+ state["activity"] = False
2274
+ try:
2275
+ # shield so the timeout doesn't cancel the future itself
2276
+ event = await asyncio.wait_for(asyncio.shield(result), timeout)
2277
+ except asyncio.TimeoutError:
2278
+ if state["activity"]:
2279
+ continue # still receiving contacts, keep waiting
2280
+ logger.debug("Timeout while getting contacts")
2281
+ return None
2282
+
2283
+ if anim:
2284
+ if event.type == EventType.CONTACTS:
2285
+ print(max(len(event.payload) - state["n"], 0) * "." + " Done")
2286
+ else:
2287
+ print(" Error")
2288
+ return event
2289
+ finally:
2290
+ for s in subs:
2291
+ s.unsubscribe()
2297
2292
 
2298
2293
  async def get_channels (mc, anim=False) :
2299
2294
  if hasattr(mc, 'channels') :
File without changes
File without changes
File without changes
File without changes
File without changes