From c7464fc615d1e7614deccbec5faf39dba3e47c1d Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Wed, 19 Jun 2024 20:50:23 +0200 Subject: [PATCH] Add Sunnylink registration check in main function The code has been adjusted to perform a check for Sunnylink registration in the main function of the sunnylinkd script. Previously, the script was checking for the SunnylinkEnabled state and if the dongle is registered at the beginning of the script. Now, these checks are executed within the main function, allowing the script to exit with a warning log if Sunnylink is not enabled. --- system/athena/sunnylinkd.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/system/athena/sunnylinkd.py b/system/athena/sunnylinkd.py index 35eb828d51..b61da2833c 100755 --- a/system/athena/sunnylinkd.py +++ b/system/athena/sunnylinkd.py @@ -190,6 +190,13 @@ def main(exit_event: threading.Event = None): except Exception: cloudlog.exception("failed to set core affinity") + is_sunnylink_enabled = params.get_bool("SunnylinkEnabled") + is_registered = params.get("SunnylinkDongleId", encoding='utf-8') not in (None, UNREGISTERED_SUNNYLINK_DONGLE_ID) + + while is_sunnylink_enabled and not is_registered: + cloudlog.info("Waiting for sunnylink registration to complete") + time.sleep(60) + UploadQueueCache.initialize(upload_queue) ws_uri = SUNNYLINK_ATHENA_HOST @@ -197,6 +204,10 @@ def main(exit_event: threading.Event = None): conn_retries = 0 while exit_event is None or not exit_event.is_set(): try: + if not is_sunnylink_enabled: + cloudlog.warning("Exiting sunnylinkd.main as SunnylinkEnabled is False") + break + if conn_start is None: conn_start = time.monotonic() @@ -228,14 +239,4 @@ def main(exit_event: threading.Event = None): if __name__ == "__main__": - is_sunnylink_enabled = params.get_bool("SunnylinkEnabled") - is_registered = params.get("SunnylinkDongleId", encoding='utf-8') not in (None, UNREGISTERED_SUNNYLINK_DONGLE_ID) - while is_sunnylink_enabled and not is_registered: - cloudlog.info("Waiting for sunnylink registration to complete") - time.sleep(60) - - if is_sunnylink_enabled: - main() - else: - cloudlog.info("Exiting sunnylinkd as SunnylinkEnabled is False") - exit(0) + main()