mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
add pending_contacts_list and track adverts and path changes
This commit is contained in:
@@ -294,10 +294,16 @@ class CommandHandler:
|
|||||||
else :
|
else :
|
||||||
out_path_hex = path
|
out_path_hex = path
|
||||||
out_path_len = int(len(path) / 2)
|
out_path_len = int(len(path) / 2)
|
||||||
|
# reflect the change
|
||||||
|
contact["out_path"] = out_path_hex
|
||||||
|
contact["out_path_len"] = out_path_len
|
||||||
out_path_hex = out_path_hex + (128-len(out_path_hex)) * "0"
|
out_path_hex = out_path_hex + (128-len(out_path_hex)) * "0"
|
||||||
|
|
||||||
if flags is None :
|
if flags is None :
|
||||||
flags = contact["flags"]
|
flags = contact["flags"]
|
||||||
|
else :
|
||||||
|
# reflect the change
|
||||||
|
contact["flags"] = flags
|
||||||
|
|
||||||
adv_name_hex = contact["adv_name"].encode().hex()
|
adv_name_hex = contact["adv_name"].encode().hex()
|
||||||
adv_name_hex = adv_name_hex + (64-len(adv_name_hex)) * "0"
|
adv_name_hex = adv_name_hex + (64-len(adv_name_hex)) * "0"
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ class MeshCore:
|
|||||||
|
|
||||||
# Initialize state (private)
|
# Initialize state (private)
|
||||||
self._contacts = {}
|
self._contacts = {}
|
||||||
|
self._contacts_ok = False
|
||||||
|
self._pending_contacts = {}
|
||||||
self._self_info = {}
|
self._self_info = {}
|
||||||
self._time = 0
|
self._time = 0
|
||||||
|
|
||||||
@@ -178,6 +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
|
||||||
|
|
||||||
|
async def _add_pending_contact(event):
|
||||||
|
c = event.payload
|
||||||
|
self._pending_contacts[c["public_key"]] = c
|
||||||
|
|
||||||
|
async def _contact_change(event):
|
||||||
|
self._contacts_ok = False
|
||||||
|
|
||||||
async def _update_self_info(event):
|
async def _update_self_info(event):
|
||||||
self._self_info = event.payload
|
self._self_info = event.payload
|
||||||
@@ -187,8 +197,11 @@ class MeshCore:
|
|||||||
|
|
||||||
# Subscribe to events to update internal state
|
# Subscribe to events to update internal state
|
||||||
self.subscribe(EventType.CONTACTS, _update_contacts)
|
self.subscribe(EventType.CONTACTS, _update_contacts)
|
||||||
|
self.subscribe(EventType.NEW_CONTACT, _add_pending_contact)
|
||||||
self.subscribe(EventType.SELF_INFO, _update_self_info)
|
self.subscribe(EventType.SELF_INFO, _update_self_info)
|
||||||
self.subscribe(EventType.CURRENT_TIME, _update_time)
|
self.subscribe(EventType.CURRENT_TIME, _update_time)
|
||||||
|
self.subscribe(EventType.ADVERTISEMENT, _contact_change)
|
||||||
|
self.subscribe(EventType.PATH_UPDATE, _contact_change)
|
||||||
|
|
||||||
# Getter methods for state
|
# Getter methods for state
|
||||||
@property
|
@property
|
||||||
@@ -196,6 +209,16 @@ class MeshCore:
|
|||||||
"""Get the current contacts"""
|
"""Get the current contacts"""
|
||||||
return self._contacts
|
return self._contacts
|
||||||
|
|
||||||
|
@property
|
||||||
|
def contacts_ok(self):
|
||||||
|
"""Get wether contact list is in sync"""
|
||||||
|
return self._contacts_ok
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pending_contacts(self):
|
||||||
|
"""Get pending contacts"""
|
||||||
|
return self._pending_contacts
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def self_info(self):
|
def self_info(self):
|
||||||
"""Get device self info"""
|
"""Get device self info"""
|
||||||
@@ -323,7 +346,7 @@ class MeshCore:
|
|||||||
|
|
||||||
async def ensure_contacts(self):
|
async def ensure_contacts(self):
|
||||||
"""Ensure contacts are fetched"""
|
"""Ensure contacts are fetched"""
|
||||||
if not self._contacts:
|
if not self._contacts or not self._contacts_ok :
|
||||||
await self.commands.get_contacts()
|
await self.commands.get_contacts()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ class MessageReader:
|
|||||||
elif packet_type_value == PacketType.CONTACT_END.value:
|
elif packet_type_value == PacketType.CONTACT_END.value:
|
||||||
await self.dispatcher.dispatch(Event(EventType.CONTACTS, self.contacts))
|
await self.dispatcher.dispatch(Event(EventType.CONTACTS, self.contacts))
|
||||||
|
|
||||||
|
|
||||||
elif packet_type_value == PacketType.SELF_INFO.value:
|
elif packet_type_value == PacketType.SELF_INFO.value:
|
||||||
self_info = {}
|
self_info = {}
|
||||||
self_info["adv_type"] = data[1]
|
self_info["adv_type"] = data[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user