From e9fc632086c546adcabc675b49291edcc77244bc Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 9 Mar 2025 21:03:21 -0400 Subject: [PATCH] this aint gonna work --- hwmonDaemon.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 38ef02f..9754fc6 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -781,19 +781,38 @@ class SystemHealthMonitor: def _parse_size(self, size_str: str) -> float: """Parse size string with units to bytes""" logger.debug(f"Parsing size string: {size_str}") - match = re.match(r'([\d.]+)\s*([KMGT])', size_str.strip()) + + # Handle empty or invalid input + if not size_str or not isinstance(size_str, str): + return 0.0 + + # Remove any whitespace and handle M/G/T units + size_str = size_str.strip() + + # Handle values with decimal points (like 192.2M) + match = re.match(r'^([\d.]+)\s*([KMGT])?', size_str) if match: value = float(match.group(1)) - unit = match.group(2) + unit = match.group(2) if match.group(2) else 'B' + multipliers = { + 'B': 1, 'K': 1024, - 'M': 1024**2, + 'M': 1024**2, 'G': 1024**3, 'T': 1024**4 } - return value * multipliers[unit] - logger.debug(f"Parsed value: {value}, Unit: {unit}, Result: {value * multipliers[unit]}") - return float(size_str) + + result = value * multipliers[unit] + logger.debug(f"Parsed value: {value}, Unit: {unit}, Result: {result}") + return result + + # If no match, try to convert directly to float + try: + return float(size_str) + except ValueError: + logger.debug(f"Could not parse size string: {size_str}") + return 0.0 def _is_physical_disk(self, device_path): """