Skip to content

Handle AMP results without a numeric prefix - #61

Open
pevd950 wants to merge 1 commit into
home-assistant-ecosystem:masterfrom
pevd950:fix-amp-text-results
Open

pevd950 wants to merge 1 commit into
home-assistant-ecosystem:masterfrom
pevd950:fix-amp-text-results

Conversation

@pevd950

@pevd950 pevd950 commented Oct 26, 2026

Copy link
Copy Markdown

In 0.11.0, an AMP result such as "No running process" makes get_ha_sensor_data() raise IndexError, interrupting the entire sensor update. The parser indexes the first match of ^\d+ even when the result has no numeric prefix. Empty strings fail the same way.

This is valid Glances output: Glances sets this result when no process matches an AMP configured with a positive minimum process count. Its AMP interface allows string results.

Use re.match() and check for a match before reading the prefix. Preserve the original result text and numeric prefixes as strings. Results without a numeric prefix get integer 0, following the existing fallback for None. This is a compatibility fallback: the result text contains no leading numeric count. The existing None result behavior stays the same.

The regression test mocks the HTTP response and exercises the real client, checking the complete sensor response for None, empty text, "No running process", other text, a numeric prefix, and a zero prefix.

Validation on macOS arm64:

  • pytest tests/ -q: 14 passed on Python 3.13.17, 3.14.9, and 3.15.0.
  • With the unchanged parser, the empty-string, "No running process", and plain-text cases fail with IndexError (3 failed, 11 passed).
  • ruff check .: passed on all three Python environments.
  • mypy glances_api: passed on Python 3.14.9.
  • git diff --check: passed.

AI assistance was used to prepare the change and tests.

@olliemaller

Copy link
Copy Markdown

@fabaff @engrbm87 this now breaks the Glances integration in Home Assistant 2026.12.0 (home-assistant/core#196391), since core ships 0.11.0. Could it go out in a 0.11.1? I'll send the core bump as soon as it's released.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants