From 4fd4b70d975b805588a0cd846c16cc14ed38c333 Mon Sep 17 00:00:00 2001 From: Gunter Tim Date: Sun, 25 Oct 2020 11:42:53 -0700 Subject: [PATCH] Added waitForConfig() method to MeshInterface --- meshtastic/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 340adc0..4a006d7 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -191,6 +191,14 @@ class MeshInterface: self._sendToRadio(toRadio) return meshPacket + def waitForConfig(self, sleep=.1, maxsecs=20, attrs=('myInfo', 'nodes', 'radioConfig')): + """Block until radio config is received. Returns True if config has been received.""" + for _ in range(int(maxsecs/sleep)): + if all(map(lambda a: getattr(self, a, None), attrs)): + return True + time.sleep(sleep) + return False + def writeConfig(self): """Write the current (edited) radioConfig to the device""" if self.radioConfig == None: