Fix hassgraph crash on empty or non-numeric HA states. - #585
Conversation
Skip invalid history states before float conversion so raw data plotting and stats no longer fail when Home Assistant returns empty strings. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a parse_state_value helper function to safely parse Home Assistant state values and refactors the codebase to use it. Feedback identifies a potential runtime crash if state is None and suggests preserving the original string instead of defaulting to 0 when rounding non-numeric states.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| val = parse_state_value(current_value) | ||
| if val == None: | ||
| val = 0 | ||
| val = round(val, decimal) | ||
| current_value = str(int(val)) if val == int(val) else str(val) |
There was a problem hiding this comment.
Converting a non-numeric state (like "unavailable") to 0 when rounding is enabled is misleading. Skip rounding and preserve the original string if parse_state_value returns None.
| val = parse_state_value(current_value) | |
| if val == None: | |
| val = 0 | |
| val = round(val, decimal) | |
| current_value = str(int(val)) if val == int(val) else str(val) | |
| val = parse_state_value(current_value) | |
| if val != None: | |
| val = round(val, decimal) | |
| current_value = str(int(val)) if val == int(val) else str(val) |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Skip invalid history states before float conversion so raw data plotting and stats no longer fail when Home Assistant returns empty strings.