fix(entities): run remaining timer callbacks on the event loop - #13
Merged
Conversation
…unsafe writes _on_time_interval (binary_sensor), _handle_scan_tick and _start (sensor) were registered with async_track_time_interval / async_call_later as plain functions, so HA ran them in a worker thread. Calling async_write_ha_state() and async_create_task() from a non-loop thread raises a non-thread-safe RuntimeError on recent HA cores (previously only a warning), crashing the update. Marking them @callback makes HA run them on the event loop. Companion to #11, which fixed the same class of bug in _handle_time_interval. Also bumps manifest version 0.5.1 -> 0.6.1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Blank line at sensor.py:147 carried trailing whitespace introduced in #11, which failed `ruff format --check` / `ruff check` in CI. Removing it makes Lint / Python green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
scripts/build.sh injects manifest.json's version into the bundle banner, so bumping the manifest to 0.6.1 left the committed hass-datapoints-cards.js stale (v0.5.1), failing the "Check built JS is up-to-date" CI job. Regenerate the version token to v0.6.1 and align package.json to match the release. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Recent Home Assistant cores promote non-thread-safe state writes from a warning to a hard
RuntimeError, which crashes the update. Three timer handlers were registered withasync_track_time_interval/async_call_lateras plain functions, so HA runs them in a worker thread:binary_sensor.py—_on_time_interval→ callsasync_write_ha_state()(this is the crash users are hitting in the field)sensor.py—_handle_scan_tick→ callsasync_create_task()(loop-only)sensor.py—_start(theasync_call_latercallback) → callsasync_track_time_interval/async_on_remove(loop-only)Observed error:
Fix
Mark all three handlers
@callbackso HA schedules them on the event loop, where these calls are safe. All three do only non-blocking, loop-affine work, so@callbackis correct (no blocking I/O moved onto the loop).The store-listener path (
_on_store_update) was audited and is fine —_notify_listeners()is only ever invoked from loop coroutines.Relationship to #11
#11 fixed the same bug class for
sensor._handle_time_interval. This completes the sweep for the remaining threeasync_track_time_interval/async_call_laterregistrations.Also
Bumps
manifest.jsonversion0.5.1→0.6.1(it had drifted behind the released tags).🤖 Generated with Claude Code