Skip to content

Handle missing time_since_update in diskio data - #59

Open
trezit wants to merge 1 commit into
home-assistant-ecosystem:masterfrom
trezit:fix/diskio-first-sample
Open

trezit wants to merge 1 commit into
home-assistant-ecosystem:masterfrom
trezit:fix/diskio-first-sample

Conversation

@trezit

@trezit trezit commented Sep 29, 2026

Copy link
Copy Markdown

Fixes #57.

Glances v4 only adds time_since_update (and the *_rate_per_sec fields) to a plugin's stats once a previous sample exists: _manage_rate returns the raw stats when stat_previous is None. The first diskio sample after the Glances server starts therefore lacks the key, and get_ha_sensor_data() raises KeyError: 'time_since_update'.

In Home Assistant, get_api() does not catch this KeyError during setup. When the host reboots and Glances and Home Assistant start together, the config entry ends in a setup error and is never retried: every Glances sensor stays unavailable until the integration is reloaded by hand. Seen with Glances 4.5.7, glances_api 0.10.0 and Home Assistant 2026.9.3 (Home Assistant's first call came 6 s after Glances started).

Change: when time_since_update is missing (or 0), keep the disk with read/write set to None, as the network sensors already do for v4. The disk has to stay in the data, because Home Assistant creates the diskio entities from the keys present in the first update. They are unavailable for that single update and get values on the next one.

A test covers the first-sample payload (values from a Glances 4.5.7 server). It fails with the KeyError without the fix. pytest, ruff check and mypy pass.

🤖 Generated with Claude Code

Glances v4 only adds "time_since_update" (and the rates) to a plugin's
stats once a previous sample exists. The first diskio sample after the
Glances server starts therefore lacks it, and get_ha_sensor_data()
raised KeyError. In Home Assistant this fails the config entry setup
for good when Glances and Home Assistant start together (host reboot).

Keep the disk with read/write set to None for that sample, like the
network sensors, so the entities are still created and get values on
the next update.

Fixes home-assistant-ecosystem#57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

KeyError: 'time_since_update' in diskio processing when Glances server has just restarted (v4 API)

1 participant