Skip to content

Fix hassgraph crash on empty or non-numeric HA states. - #585

Merged
tavdog merged 4 commits into
mainfrom
fix/hassgraph-empty-state
Jul 10, 2026
Merged

Fix hassgraph crash on empty or non-numeric HA states.#585
tavdog merged 4 commits into
mainfrom
fix/hassgraph-empty-state

Conversation

@tavdog

@tavdog tavdog commented Jul 10, 2026

Copy link
Copy Markdown
Member

Skip invalid history states before float conversion so raw data plotting and stats no longer fail when Home Assistant returns empty strings.

tavdog and others added 2 commits July 10, 2026 08:37
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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/hassgraph/hass_graph.star Outdated
Comment on lines +273 to 277
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

tavdog and others added 2 commits July 10, 2026 08:44
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@tavdog
tavdog merged commit e87e9c7 into main Jul 10, 2026
6 checks passed
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.

1 participant