mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
remove anim in get contacts
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "meshcore"
|
name = "meshcore"
|
||||||
version = "2.1.15"
|
version = "2.1.16"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
||||||
{ name="Alex Wolden", email="awolden@gmail.com" },
|
{ name="Alex Wolden", email="awolden@gmail.com" },
|
||||||
|
|||||||
@@ -9,17 +9,17 @@ logger = logging.getLogger("meshcore")
|
|||||||
|
|
||||||
|
|
||||||
class ContactCommands(CommandHandlerBase):
|
class ContactCommands(CommandHandlerBase):
|
||||||
async def get_contacts(self, lastmod=0, anim=False) -> Event:
|
async def get_contacts_async(self, lastmod=0) :
|
||||||
logger.debug("Getting contacts")
|
logger.debug("Getting contacts")
|
||||||
data = b"\x04"
|
data = b"\x04"
|
||||||
if lastmod > 0:
|
if lastmod > 0:
|
||||||
data = data + lastmod.to_bytes(4, "little")
|
data = data + lastmod.to_bytes(4, "little")
|
||||||
if anim:
|
|
||||||
print("Fetching contacts ", end="", flush=True)
|
|
||||||
# wait first event
|
# wait first event
|
||||||
res = await self.send(data)
|
await self.send(data)
|
||||||
timeout = 5
|
|
||||||
contact_nb = 0
|
async def get_contacts(self, lastmod=0, timeout=5) -> Event:
|
||||||
|
await self.get_contacts_async(lastmod)
|
||||||
|
|
||||||
# Inline wait for events to continue waiting for CONTACTS event
|
# Inline wait for events to continue waiting for CONTACTS event
|
||||||
# while receiving NEXT_CONTACTs (or it might be missed over serial)
|
# while receiving NEXT_CONTACTs (or it might be missed over serial)
|
||||||
try:
|
try:
|
||||||
@@ -40,30 +40,20 @@ class ContactCommands(CommandHandlerBase):
|
|||||||
|
|
||||||
# Check if any future completed successfully
|
# Check if any future completed successfully
|
||||||
if len(done) == 0:
|
if len(done) == 0:
|
||||||
print(" Timeout")
|
logger.debug("Timeout while getting contacts")
|
||||||
for future in pending: # cancel all futures
|
for future in pending: # cancel all futures
|
||||||
future.cancel()
|
future.cancel()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for future in done:
|
for future in done:
|
||||||
event = await future
|
event = await future
|
||||||
|
if event is None or event.type != EventType.NEXT_CONTACT:
|
||||||
if event:
|
for future in pending:
|
||||||
if event.type == EventType.NEXT_CONTACT:
|
future.cancel()
|
||||||
if anim:
|
return event
|
||||||
contact_nb = contact_nb+1
|
|
||||||
print(".", end="", flush=True)
|
|
||||||
else: # Done or Error ... cancel pending and return
|
|
||||||
if anim:
|
|
||||||
if event.type == EventType.CONTACTS:
|
|
||||||
print ((len(event.payload)-contact_nb)*"." + " Done")
|
|
||||||
else :
|
|
||||||
print(" Error")
|
|
||||||
for future in pending:
|
|
||||||
future.cancel()
|
|
||||||
return event
|
|
||||||
|
|
||||||
futures = []
|
futures = []
|
||||||
|
|
||||||
for future in pending: # put back pending
|
for future in pending: # put back pending
|
||||||
futures.append(future)
|
futures.append(future)
|
||||||
|
|
||||||
@@ -74,13 +64,9 @@ class ContactCommands(CommandHandlerBase):
|
|||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.debug(f"Timeout receiving contacts")
|
logger.debug(f"Timeout receiving contacts")
|
||||||
if anim:
|
|
||||||
print(" Timeout")
|
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Command error: {e}")
|
logger.debug(f"Command error: {e}")
|
||||||
if anim:
|
|
||||||
print(" Error")
|
|
||||||
return Event(EventType.ERROR, {"error": str(e)})
|
return Event(EventType.ERROR, {"error": str(e)})
|
||||||
|
|
||||||
async def reset_path(self, key: DestinationType) -> Event:
|
async def reset_path(self, key: DestinationType) -> Event:
|
||||||
|
|||||||
Reference in New Issue
Block a user