ha-coordinator-debug
Diagnose and fix runtime problems in this Home Assistant custom integration — entities showing "unavailable" or "unknown", stale data, the integration failing to set up, "Config entry not ready", repeated reauth prompts, coordinator update failures, timeouts, or blocking-call warnings. Use when asked to "debug", "why is my sensor unavailable", "the integration won't load", "data isn't updating", "check the logs", "restart Home Assistant", or when investigating anything in coordinator/, api/, or the setup path. Covers the run loop, `script/ha`, when to read `config/.storage/` instead, and the coordinator failure contract. SYMPTOMS — load this if you are about to: invent your own `hass`/`pytest` command instead of the project scripts; read or write `config/.storage/` while Home Assistant is running; ask the developer to read a state or download diagnostics from the UI for you; return None from `_async_update_data` to signal failure; or catch Exception broadly in the coordinator.
- License 许可
- MIT
- 所属仓库
- amg0/ha_ksenia
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- ha-coordinator-debug
- description
- Diagnose and fix runtime problems in this Home Assistant custom integration — entities showing "unavailable" or "unknown", stale data, the integration failing to set up, "Config entry not ready", repeated reauth prompts, coordinator update failures, timeouts, or blocking-call warnings. Use when asked to "debug", "why is my sensor unavailable", "the integration won't load", "data isn't updating", "check the logs", "restart Home Assistant", or when investigating anything in coordinator/, api/, or the setup path. Covers the run loop, `script/ha`, when to read `config/.storage/` instead, and the coordinator failure contract. SYMPTOMS — load this if you are about to: invent your own `hass`/`pytest` command instead of the project scripts; read or write `config/.storage/` while Home Assistant is running; ask the developer to read a state or download diagnostics from the UI for you; return None from `_async_update_data` to signal failure; or catch Exception broadly in the coordinator.
02 资源文件 1
- 参考文档references/async-rules.md6.6 KB
03 SKILL.md 正文
Debug the running integration
Work from evidence, not from guesses. The order below is deliberate: reproduce, read the log, localise to a layer, then fix.
| File | When to read |
|---|---|
references/async-rules.md |
A blocking-call warning, a thread-safety error, or a hang with no traceback behind it |
1. Reproduce with a clean instance
Always use the project scripts — hand-rolled hass or pip invocations miss the venv, PYTHONPATH, port cleanup, and
debugpy setup, and are the single most common cause of agents getting stuck.
./script/develop
If Home Assistant is unresponsive or the port is held:
pkill -f "hass --config" || true && pkill -f "debugpy.*5678" || true && ./script/develop
Restart after any change to Python files, manifest.json, services.yaml, translations, or the config flow.
Once it is up, script/ha reads the instance directly — entity states,
config entry status, diagnostics, the error log — so nothing below depends on asking the developer to look something
up in the UI. It authenticates itself; there is no token to set up.
script/ha status # reachable, and which version
script/ha entries # did the config entry actually load
The instance is shared
The developer restarts Home Assistant, clicks through the UI, and tries things out while you work — often precisely because you are busy. Never carry the instance's run state from one step to the next. Observe it.
script/ha status # exit 0 up, exit 2 down; `started` and `uptime` reveal a restart you did not do
- A changed run state is the expected case, not a fault. Running when you left it stopped means the developer
started it. Do not go through
ps, the process tree, or the log looking for an explanation — start it, or re-run your command, and carry on. - Spend at most one re-check on it. If it still does not add up, say what you observed and continue with the task. Reconciling who started what is never the task.
./script/developtakes the instance over — it is not "start it if it is not running". It kills whatever is already bound toconfig/and starts its own, by design, because the log has to stream into the terminal that launched it. So the developer's terminal falls silent, and the live log they were watching is gone. Checkscript/ha statusfirst and simply use the instance that is already there. Runscript/developonly when it is genuinely down, or when a change to Python,manifest.json,services.yaml, translations or the config flow forces a restart — and say that you are doing it. Never restart to tidy up.- The same happens in reverse, and is equally fine: when the developer runs
./script/develop, the instance you started dies and whatever file you were writing its log to stops growing. Treat that as normal and re-orient. - Announce it before you take exclusive control, so the developer knows to keep their hands off meanwhile. That
covers
script/setup/reset,script/ha token --rotateand--revoke, and any loop that restarts repeatedly — all of them need Home Assistant stopped or undisturbed. ha call,ha flow,ha reloadandha loglevelchange what the developer sees. Cheap and reversible, but a config entry created by a flow stays until someone removes it.- State the run state when you finish — after checking it, never from memory.
Ask the instance, or read the files?
There are two sources of truth for runtime state, and which one is correct depends only on whether Home Assistant is running. Getting this backwards is the most common way to debug a ghost.
While Home Assistant runs, the API is authoritative and the files under config/.storage/ are stale by design —
they are Store.async_delay_save files, written some time after the change they describe:
| What | Written |
|---|---|
| entity / device / area registry | 10 s after a change — but 180 s during startup |
| config entries | 1 s after a change |
core.restore_state |
every 15 minutes, and on shutdown |
home-assistant_v2.db (recorder) |
every commit_interval seconds — 30 s here |
So a registry entry you just created can be missing from core.entity_registry for three minutes, and live state is
in none of these files at all — core.restore_state is a periodic snapshot, and the recorder holds history, not the
present.
| Question | Use |
|---|---|
| What is this entity's state right now | script/ha states / entity |
| Did the entry load, and why not | script/ha entries |
| What unique IDs / registry flags does it have | script/ha entities |
| What does the coordinator actually hand out | script/ha diagnostics |
| Did an error happen | script/ha logs, then the log file |
| Startup order, full traceback, surrounding context | config/home-assistant.log |
| The previous run | config/home-assistant.log.1 |
| What a migration persisted | config/.storage/* — with HA stopped |
| Whether a value changed over the last hours | script/ha watch, or the recorder database |
Reading the raw files is right when Home Assistant is stopped: post-mortem analysis, checking what a config entry
migration actually wrote, or diffing .storage before and after a change. Then they are the only source, and they are
accurate.
Never write into config/.storage/ while Home Assistant is running. It holds every store in memory and rewrites
the whole file on its next save, so your edit is discarded — silently, minutes later. script/setup/seed-auth takes
Home Assistant's own .ha_run.lock for exactly this reason. config/.storage/auth and dev_access_token are
additionally read-denied: they are credentials, not debugging material.
2. Read the log
Start with the structured log — it is deduplicated, counts repeats, and keeps each traceback attached to its record:
script/ha logs --level error # then widen to --level warning
script/ha logs --grep coordinator
The raw stream is still there when you need surrounding context: live in the terminal running ./script/develop, and
in config/home-assistant.log (previous run in config/home-assistant.log.1).
rg -n "<domain>|Traceback|ERROR|WARNING" config/home-assistant.log | tail -50
Raise verbosity without restarting — this takes effect immediately:
script/ha loglevel custom_components.<domain>=debug homeassistant.helpers.update_coordinator=debug
It does not survive a restart. For a level that should, put it in config/configuration.yaml and restart:
logger:
default: warning
logs:
custom_components.<domain>: debug
Read the first error in a cascade, not the last. A wall of "Error doing job" usually has one root cause above it.
Two debug modes catch what no log level shows: Home Assistant's own, and asyncio's. With both on, calling an async_*
API from the wrong thread and blocking the event loop are reported the moment they happen, instead of surfacing later
as an unexplained hang or a state that quietly went wrong.
A debug_console: line in config/configuration.yaml (HA 2026.11+) adds a Python console under Settings >
Tools, with hass in scope — quicker than a log line and a restart for inspecting live objects. It runs in the event
loop, so never call anything blocking there.
A config flow missing after a restart is usually the frontend cache, not the code. Hard-refresh the browser before debugging the flow.
3. Localise the failure
Each symptom has one command that produces the evidence, so you are reading state rather than guessing at it.
| Symptom | Command | Layer to inspect |
|---|---|---|
| Integration missing from the add-integration list | script/ha setup-info |
manifest.json, import error at module load — check the log at startup |
| "Config entry not ready, retrying" | script/ha entries |
_async_update_data / _async_setup raising ConfigEntryNotReady |
Entry loads, all entities unavailable |
script/ha states |
coordinator's first refresh failed, or last_update_success false |
Entities available but values unknown/None |
script/ha entity sensor.<id> |
key mismatch between coordinator.data and the entity's read path |
| Values never change | script/ha watch --seconds 120 |
update_interval, caching in the API client, or a swallowed error |
| Endless reauth prompts | script/ha entries |
ConfigEntryAuthFailed raised for a non-auth failure |
| Config flow rejects valid input | script/ha flow start |
see ha-config-flow |
| "Detected blocking call inside the event loop" | script/ha logs --level warning |
sync I/O in async code — see ha-modern-apis |
| Entity duplicated after an update | script/ha entities |
unique_id changed — see ha-breaking-changes |
script/ha entries prints the entry state and its reason — the same text the UI shows, which is usually the whole
diagnosis for a setup failure.
script/ha watch deserves care: Home Assistant fires state_changed only when the state or an attribute genuinely
changes, so an empty watch is a finding, not a failed measurement. It means the coordinator is handing back identical
data, not that notification is broken.
Cross-check the actual payload rather than assuming its shape:
LOGGER.debug("Coordinator data: %s", self.data)
script/ha diagnostics | jq .data shows the same payload without an edit and a restart, whenever the integration
implements diagnostics.
4. Check the failure contract
_async_update_data communicates through exception type, and getting it wrong is the root of most availability bugs.
The exception mapping table is in
blueprint.coordinator.instructions.md. Read the
coordinator against it and check for the four failures that table cannot express:
- Signalling failure by returning
Noneor an empty dict instead of raising. Entities then showunknownforever instead of going unavailable, and nothing retries. - A broad
except Exceptionthat swallows the auth error, so reauth never triggers and the entry just looks broken. The OAuth2 helper's token errors are the same trap — see the instructions file's Authentication rules. - Logging on every failed poll. The coordinator logs the first failure and then stays quiet by design
(
log-when-unavailable, Silver). Manual logging buries the real error in repetition. ConfigEntryNotReadyraised outside setup, orasync_config_entry_first_refresh()called outside setup.
5. Common fixes
Update interval too aggressive — the Bronze appropriate-polling rule. Local devices ~30 s, cloud services
~5–15 min, fixed in code — never a user option
(blueprint.config_flow).
Timeouts — every request needs one, with asyncio.timeout, never a bare await:
async with asyncio.timeout(10):
response = await self._session.get(url)
Partial data — when only part of the payload is missing, keep the previous value instead of dropping the whole update; only raise when the update is genuinely useless.
Entity reads the wrong key — compare the EntityDescription.key / value_fn against the logged payload.
Setup ordering — expensive one-off work (fetching device metadata, capabilities) belongs in _async_setup(), which
runs once before the first refresh, not in _async_update_data.
A listener or reconnect loop that outlives an unload — start it with
entry.async_create_background_task(hass, coro, name), which is cancelled when the entry unloads and does not hold up
startup. hass.async_create_task survives the unload and keeps running against a dead entry.
6. Confirm the fix
script/lint && script/type-check
script/test
Restart, reproduce the original scenario, and confirm the log is clean:
pkill -f "hass --config" && ./script/develop # any change to a .py file needs this
script/ha entries # state: loaded, reason: -
script/ha states # the values you expected
script/ha logs --level warning # nothing new
If the failure was data-shaped, check the payload directly — script/ha diagnostics | jq .data should now show the
corrected structure. Diagnostics must run everything through async_redact_data(); if you added a field, make sure it
is redacted when sensitive.
script/ha reload is the shortcut when the change is confined to entry data or options — it reloads the config entry
without restarting the instance. It does not re-import Python, so it is never a substitute for a restart after a
code edit.
7. Add a regression test
A runtime bug that reached a user is exactly the case where a test pays for itself. Add one that reproduces the
original failure before the fix. See ha-testing.
Stop conditions
After three failed attempts at the same error, stop and report what you tried and what you observed. Do not keep looping — a wrong mental model does not improve with repetition.
04 同仓库更多 Skills
issues
Triage/fix the GitHub issue backlog via branch + PR, with auto-merge on green CI for this session.
ha-translations
Add or fix user-facing strings for this Home Assistant custom integration — translations/en.json and other languages, icons.json, entity names and states, config flow labels and errors, service action descriptions, exception messages, and repair issue text. Use when asked to "update translations", "add a translation key", "translate", "fix the entity name", "add strings for the new sensor/action/option", "add icons", or when hassfest reports a missing or unused translation key. Covers the key structure, which keys each feature needs, placeholders, the icons.json contract, and the project's strict rule about only touching en.json. SYMPTOMS — load this if you are about to: write user-facing English into Python; edit a language file other than `en.json`; add an entity without its `entity.<platform>.<key>.name` key; skip `data_description` on a config flow field; or set `icon=` instead of using `icons.json`.
ha-testing
Write, fix, or extend automated tests for this Home Assistant custom integration using pytest and pytest-homeassistant-custom-component. Use when asked to "add tests", "write a test", "the tests fail", "improve coverage", "add a regression test", "test the config flow", "update snapshots", or when a behavioural change needs verification before it can be called done. Covers the tests/ layout, the conftest.py fixtures this project needs, mocking the API client, config flow and entity test patterns, registry assertions, syrupy snapshots, freezing time, and the script/test commands. SYMPTOMS — load this if you are about to: instantiate an entity class directly instead of asserting on `hass.states`; write a test without `enable_custom_integrations`; use `time.sleep` instead of `async_fire_time_changed`; silence a DeprecationWarning to make the suite pass; or commit a snapshot you have not read.
ha-service-action
Add, change, or remove a Home Assistant service action (also called a "service" or "action") in this custom integration. Use when asked to "add a service", "add an action", "expose X as a service call", "add a service that returns data", "make this callable from an automation", or when editing services.yaml, the service_actions/ package, service schemas, service response data, or the async_setup() registration. Covers the services.yaml contract, probatio schemas, selectors, entity/device targeting, response data, translated error messages, and the Bronze quality-scale rule that actions must be registered in async_setup(). SYMPTOMS — load this if you are about to: register an action in `async_setup_entry()`; add a `services.yaml` field without a selector; add an `entity_id` field where `target:` belongs; raise a plain English `HomeAssistantError`; or swallow an action failure into a log line.
ha-release
Cut a release of this Home Assistant custom integration, or prepare the commits that feed it. Use when asked to "release", "cut a version", "bump the version", "prepare release notes", "what will the next version be", "write a commit message", "why didn't release-please pick this up", or when reviewing whether a change is user-facing. Covers the Conventional Commits rules commitlint enforces here, how release-please derives the version and changelog, the pre-1.0 bump rules, script/version and script/release-notes, skipping a commit from the notes, and the commit rules this project enforces for agents. SYMPTOMS — load this if you are about to: commit without an explicit request; offer to `git push`; label a user-facing fix as `chore` (chore, like every hidden type, never reaches the changelog and never triggers a release); write a commit subject over 100 characters or in sentence case; or edit the version in `manifest.json` by hand.
ha-quality-review
Perform a structured quality review of this Home Assistant custom integration, either as a full audit or scoped to a diff. Use when asked to "review the integration", "audit the code", "check quality scale", "are we bronze/silver/gold", "is this ready to release", "review my changes", "what's missing before publishing", or before opening a pull request that touches integration code. Covers running the automated gates first, then auditing architecture, the Integration Quality Scale rules, error handling, security, performance, user experience, and documentation — and reporting findings ranked by severity with concrete fixes. SYMPTOMS — load this if you are about to: report a review that only restates linter output; claim real-device testing that did not happen; give a finding without a file path and a fix; or judge quality without running `script/hassfest` and the test suite first.