From 33b7513c8d75bda6099f1ae840fe09085aa19d39 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Mon, 3 Nov 2025 19:33:05 +0100 Subject: [PATCH] refactor(statsd): improve `sp_stats` error handling and param processing - Enhanced exception handling for `params.get` to prevent crashes. - Added support for nested dict values to be included in stats. --- sunnypilot/sunnylink/statsd.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sunnypilot/sunnylink/statsd.py b/sunnypilot/sunnylink/statsd.py index f12d260f51..60e9b30e55 100755 --- a/sunnypilot/sunnylink/statsd.py +++ b/sunnypilot/sunnylink/statsd.py @@ -28,7 +28,7 @@ from common.realtime import Ratekeeper def sp_stats(end_event): """Collect Sunnypilot-specific statistics and send as raw metrics.""" - rk = Ratekeeper(1, print_delay_threshold=None) + rk = Ratekeeper(.1, print_delay_threshold=None) statlogsp = StatLogSP(intercept=False) params = Params() @@ -60,11 +60,22 @@ def sp_stats(end_event): while not end_event.is_set(): try: for key in param_keys: - value = params.get(key) - if value is not None: + + try: + value = params.get(key) + except Exception as e: + stats_dict[key] = e + continue + + if value is None: + continue + + if isinstance(value, dict): + for subkey, subval in value.items(): + stats_dict[f"{key}.{subkey}"] = subval + else: stats_dict[key] = value - # Send as raw metric (will be base64 encoded in the main loop) if stats_dict: statlogsp.raw('sunnypilot_params', stats_dict) except Exception as e: