From 7ba3d7ba01e4aad3915572eafeca535138c915ab Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 9 Mar 2025 20:40:54 -0400 Subject: [PATCH] debug parse --- hwmonDaemon.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 7be94a0..28cfc49 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -778,11 +778,14 @@ 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}") + if not size_str: return 0.0 # Handle decimal numbers with units (like 192.2M, 3.5G) - match = re.match(r'([\d.]+)\s*([KMGT])', size_str.strip()) + # Also handle cases with spaces between number and unit + match = re.match(r'([\d.]+)\s*([KMGT])(?:iB|B)?', size_str.strip()) if match: value = float(match.group(1)) unit = match.group(2) @@ -792,13 +795,30 @@ class SystemHealthMonitor: 'G': 1024**3, 'T': 1024**4 } - return value * multipliers[unit] - - # Remove any non-numeric characters and try parsing - cleaned = ''.join(c for c in size_str if c.isdigit() or c == '.') + result = value * multipliers[unit] + logger.debug(f"Parsed {size_str} to {result} bytes") + return result + + # Handle cases like '957.2M' + match = re.match(r'([\d.]+)([KMGT])', size_str.strip()) + if match: + value = float(match.group(1)) + unit = match.group(2) + multipliers = { + 'K': 1024, + 'M': 1024**2, + 'G': 1024**3, + 'T': 1024**4 + } + result = value * multipliers[unit] + logger.debug(f"Parsed {size_str} to {result} bytes") + return result + + # Try parsing as plain number try: - return float(cleaned) + return float(size_str) except ValueError: + logger.debug(f"Failed to parse size string: {size_str}") return 0.0 def _is_physical_disk(self, device_path):