From 065096455915cb46b0f67e9bf1cc4f87f19e07f2 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 13 Feb 2026 23:39:55 -0500 Subject: [PATCH] [TIZI/TICI] ui: only fetch roles and users when the sunnylink panel is opened (#1697) * sunnylink: only roles and users when the sunnylink panel is opened * shadow * thread-safe --- .../sunnypilot/layouts/settings/sunnylink.py | 5 +++++ sunnypilot/sunnylink/sunnylink_state.py | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py index 00baf0cccf..7955f13202 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py @@ -355,5 +355,10 @@ class SunnylinkLayout(Widget): def show_event(self): super().show_event() + ui_state.sunnylink_state.set_settings_open(True) self._scroller.show_event() self._sunnylink_description.set_visible(False) + + def hide_event(self): + super().hide_event() + ui_state.sunnylink_state.set_settings_open(False) diff --git a/sunnypilot/sunnylink/sunnylink_state.py b/sunnypilot/sunnylink/sunnylink_state.py index acd20d23ae..927d041991 100644 --- a/sunnypilot/sunnylink/sunnylink_state.py +++ b/sunnypilot/sunnylink/sunnylink_state.py @@ -109,6 +109,8 @@ class SunnylinkState: self.sunnylink_dongle_id = self._params.get("SunnylinkDongleId") self._api = SunnylinkApi(self.sunnylink_dongle_id) + self._panel_open = False + self._load_initial_state() def _load_initial_state(self) -> None: @@ -166,10 +168,14 @@ class SunnylinkState: def _worker_thread(self) -> None: while self._running: - self._sm.update() - if self.is_connected(): - self._fetch_roles() - self._fetch_users() + with self._lock: + panel_open = self._panel_open + + if panel_open: + self._sm.update() + if self.is_connected(): + self._fetch_roles() + self._fetch_users() for _ in range(int(self.FETCH_INTERVAL / self.SLEEP_INTERVAL)): if not self._running: @@ -221,5 +227,9 @@ class SunnylinkState: else: return style.ITEM_TEXT_VALUE_COLOR + def set_settings_open(self, _open: bool) -> None: + with self._lock: + self._panel_open = _open + def __del__(self): self.stop()