Skip to content

Wrong battery percent detecttion #8

Description

@ToFpon

In big-hardware-info/src/big_hardware_info/collectors/inxi_parser.py you have

                charge = 0
                if "charge" in cleaned:
                    charge_str = str(cleaned["charge"])
                    match = re.search(r"(\d+(?:\.\d+)?)", charge_str)
                    if match:
                        charge = float(match.group(1))

and it give a wrong battery percent.
Change it to

                charge = 0
                if "charge" in cleaned:
                    charge_str = str(cleaned["charge"])
                    # Prefer the percentage inside parentheses: "54.0 Wh (98.4%)"
                    match = re.search(r"\((\d+(?:\.\d+)?)\s*%\)", charge_str)
                    if not match:
                        # Direct form for peripherals: "100%"
                        match = re.search(r"(\d+(?:\.\d+)?)\s*%", charge_str)
                    if not match:
                        # Fallback: first number (edge cases)
                        match = re.search(r"(\d+(?:\.\d+)?)", charge_str)
                    if match:
                        charge = float(match.group(1))

and all this good ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions