diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 1a9790d..fa8ef14 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -777,38 +777,30 @@ class SystemHealthMonitor: return False def _parse_size(self, size_str: str) -> float: - """ - Parse size string with units to float value - Examples: '44.9G', '1.9G', '192.2M', '5.3T' - """ - if not size_str or not isinstance(size_str, str): + """Parse size string with units to float value""" + if not size_str: return 0.0 + + # Handle M/G/T sizes with potential decimal points + 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 + } + return value * multipliers[unit] - # Remove any spaces and normalize format - size_str = size_str.strip().upper() - - # Define unit multipliers - units = { - 'B': 1, - 'K': 1024, - 'M': 1024**2, - 'G': 1024**3, - 'T': 1024**4, - 'P': 1024**5 - } - + # Try parsing as plain number try: - # Extract numeric value and unit - match = re.match(r'^([\d.]+)([BKMGTP])$', size_str) - if match: - value = float(match.group(1)) - unit = match.group(2) - return value * units[unit] return float(size_str) - except (ValueError, AttributeError): - logger.debug(f"Could not parse size: {size_str}") + except ValueError: return 0.0 + def _is_physical_disk(self, device_path): """ Check if the device is a physical disk, excluding logical volumes and special devices.