mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-14 21:26:54 +00:00
some changes on managing pending contacts
This commit is contained in:
@@ -43,7 +43,7 @@ class MeshCore:
|
|||||||
|
|
||||||
# Initialize state (private)
|
# Initialize state (private)
|
||||||
self._contacts = {}
|
self._contacts = {}
|
||||||
self._contacts_ok = False
|
self._contacts_dirty = True
|
||||||
self._pending_contacts = {}
|
self._pending_contacts = {}
|
||||||
self._self_info = {}
|
self._self_info = {}
|
||||||
self._time = 0
|
self._time = 0
|
||||||
@@ -180,14 +180,14 @@ class MeshCore:
|
|||||||
"""Set up event subscriptions to track data internally"""
|
"""Set up event subscriptions to track data internally"""
|
||||||
async def _update_contacts(event):
|
async def _update_contacts(event):
|
||||||
self._contacts = event.payload
|
self._contacts = event.payload
|
||||||
self._contacts_ok = True
|
self._contacts_dirty = False
|
||||||
|
|
||||||
async def _add_pending_contact(event):
|
async def _add_pending_contact(event):
|
||||||
c = event.payload
|
c = event.payload
|
||||||
self._pending_contacts[c["public_key"]] = c
|
self._pending_contacts[c["public_key"]] = c
|
||||||
|
|
||||||
async def _contact_change(event):
|
async def _contact_change(event):
|
||||||
self._contacts_ok = False
|
self._contacts_dirty = True
|
||||||
|
|
||||||
async def _update_self_info(event):
|
async def _update_self_info(event):
|
||||||
self._self_info = event.payload
|
self._self_info = event.payload
|
||||||
@@ -210,14 +210,9 @@ class MeshCore:
|
|||||||
return self._contacts
|
return self._contacts
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def contacts_ok(self):
|
def contacts_dirty(self):
|
||||||
"""Get wether contact list is in sync"""
|
"""Get wether contact list is in sync"""
|
||||||
return self._contacts_ok
|
return self._contacts_dirty
|
||||||
|
|
||||||
@property
|
|
||||||
def pending_contacts(self):
|
|
||||||
"""Get pending contacts"""
|
|
||||||
return self._pending_contacts
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def self_info(self):
|
def self_info(self):
|
||||||
@@ -244,6 +239,17 @@ class MeshCore:
|
|||||||
"""Set the default timeout for commands"""
|
"""Set the default timeout for commands"""
|
||||||
self.commands.default_timeout = value
|
self.commands.default_timeout = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pending_contacts(self):
|
||||||
|
"""Get pending contacts"""
|
||||||
|
return self._pending_contacts
|
||||||
|
|
||||||
|
def pop_pending_contact(self, key):
|
||||||
|
return self._pending_contacts.pop(key, None)
|
||||||
|
|
||||||
|
def flush_pending_contacts(self): # would be interesting to have a time param
|
||||||
|
self._pending_contacts = {}
|
||||||
|
|
||||||
def get_contact_by_name(self, name) -> Optional[Dict[str, Any]]:
|
def get_contact_by_name(self, name) -> Optional[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Find a contact by its name (adv_name field)
|
Find a contact by its name (adv_name field)
|
||||||
@@ -346,7 +352,7 @@ class MeshCore:
|
|||||||
|
|
||||||
async def ensure_contacts(self, follow=False):
|
async def ensure_contacts(self, follow=False):
|
||||||
"""Ensure contacts are fetched"""
|
"""Ensure contacts are fetched"""
|
||||||
if not self._contacts or (follow and not self._contacts_ok) :
|
if not self._contacts or (follow and self._contacts_dirty) :
|
||||||
await self.commands.get_contacts()
|
await self.commands.get_contacts()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user