mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-23 23:02:04 +08:00
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.
This commit is contained in:
+12
-11
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user