mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-01 16:58:06 +00:00
fix: initialise wifi-status throttle state in __init__
Codacy (pylint access-member-before-definition) on #403: the throttled early-return read _wifi_status_last_result relying on the non-local invariant that the first call always passes the throttle window and assigns it. Correct at runtime, but fragile — initialise both throttle fields in the constructor and drop the getattr fallback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FqzC1nzTWL4kaqgMaQZFam
This commit is contained in:
@@ -199,6 +199,10 @@ class DisplayController:
|
|||||||
self.wifi_status_file = WIFI_STATUS_FILE
|
self.wifi_status_file = WIFI_STATUS_FILE
|
||||||
self.wifi_status_active = False
|
self.wifi_status_active = False
|
||||||
self.wifi_status_expires_at: Optional[float] = None
|
self.wifi_status_expires_at: Optional[float] = None
|
||||||
|
# _check_wifi_status_message throttle state (checked at frame rate,
|
||||||
|
# stat'd at most once per second)
|
||||||
|
self._wifi_status_check_ts = 0.0
|
||||||
|
self._wifi_status_last_result: Optional[Dict[str, Any]] = None
|
||||||
|
|
||||||
# Plugin display() signature cache — must be initialised before the plugin
|
# Plugin display() signature cache — must be initialised before the plugin
|
||||||
# loading loop below so the .pop() invalidation at load time is always safe.
|
# loading loop below so the .pop() invalidation at load time is always safe.
|
||||||
@@ -2357,8 +2361,9 @@ class DisplayController:
|
|||||||
# Throttle the existence stat to ~1 Hz: this runs on every render
|
# Throttle the existence stat to ~1 Hz: this runs on every render
|
||||||
# iteration (60+ fps), and the file usually doesn't exist — the
|
# iteration (60+ fps), and the file usually doesn't exist — the
|
||||||
# status message's lifetime is measured in seconds anyway.
|
# status message's lifetime is measured in seconds anyway.
|
||||||
|
# Both attributes are initialised in __init__.
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if (now - getattr(self, '_wifi_status_check_ts', 0.0)) < 1.0:
|
if (now - self._wifi_status_check_ts) < 1.0:
|
||||||
return self._wifi_status_last_result
|
return self._wifi_status_last_result
|
||||||
self._wifi_status_check_ts = now
|
self._wifi_status_check_ts = now
|
||||||
self._wifi_status_last_result = None
|
self._wifi_status_last_result = None
|
||||||
|
|||||||
Reference in New Issue
Block a user