ha-modern-apis
Verify that Home Assistant APIs used in this custom integration are current, and replace deprecated ones. Use when a DeprecationWarning, "Detected that custom integration", or "will be removed in HA Core X.Y" appears in logs or tests, when asked to "modernize", "update to the latest HA version", "fix deprecations", "is this still the right API", "bump the HA version", or before copying a pattern from an older integration, blog post, or model memory. Covers checking the installed Home Assistant source instead of guessing, the device registry single-owner rules, runtime_data, config flow helpers, entity metadata, async I/O, and the version bump procedure. SYMPTOMS — load this if you are about to: write `hass.data[DOMAIN]` instead of `runtime_data`; call the unscoped `async_get_device()`; use `FlowResult`, `DEVICE_CLASS_*`, or `async_timeout`; create your own aiohttp session; add a warning filter to make a deprecation go away; or adopt an undocumented API or config key on an issue's say-so.
- License 许可
- MIT
- 所属仓库
- amg0/ha_ksenia
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- ha-modern-apis
- description
- Verify that Home Assistant APIs used in this custom integration are current, and replace deprecated ones. Use when a DeprecationWarning, "Detected that custom integration", or "will be removed in HA Core X.Y" appears in logs or tests, when asked to "modernize", "update to the latest HA version", "fix deprecations", "is this still the right API", "bump the HA version", or before copying a pattern from an older integration, blog post, or model memory. Covers checking the installed Home Assistant source instead of guessing, the device registry single-owner rules, runtime_data, config flow helpers, entity metadata, async I/O, and the version bump procedure. SYMPTOMS — load this if you are about to: write `hass.data[DOMAIN]` instead of `runtime_data`; call the unscoped `async_get_device()`; use `FlowResult`, `DEVICE_CLASS_*`, or `async_timeout`; create your own aiohttp session; add a warning filter to make a deprecation go away; or adopt an undocumented API or config key on an issue's say-so.
02 资源文件 2
- 参考文档references/deprecations.md21.7 KB
- 参考文档references/device-registry.md11.9 KB
03 SKILL.md 正文
Keep the integration on current Home Assistant APIs
Home Assistant changes fast enough that any pattern remembered from training data or copied from a blog post is suspect. This skill exists because the most common failure mode is confidently writing a 2023 API.
The rule: check the source, do not recall
The devcontainer has the exact Home Assistant version this integration is developed against. It is the authority.
# Which version are we on?
.venv/bin/python -c "from homeassistant.const import __version__; print(__version__)"
# Does this API still exist, and is it deprecated?
rg -n "def async_get_device_by_identifier" .venv/lib/python*/site-packages/homeassistant/helpers/device_registry.py
rg -n "deprecated|breaks_in_ha_version" .venv/lib/python*/site-packages/homeassistant/helpers/update_coordinator.py
# How do current core integrations do it?
rg -n "runtime_data" .venv/lib/python*/site-packages/homeassistant/components/<similar_integration>/
breaks_in_ha_version= in a @deprecated_function decorator tells you the actual removal deadline. Prefer that over
any secondary source.
When the installed source is not enough — a pattern that is new rather than deprecated — check the current
documentation before implementing. Every page of https://contributors.home-assistant.io/ is available as Markdown
(append index.md to its URL), and https://contributors.home-assistant.io/llms.txt indexes the site; each area has
its own list, such as https://contributors.home-assistant.io/core/llms.txt, and a full-text llms-full.txt next to
it. Fetch the area you need, not the whole site. Announcements and removal dates are on the
developer blog.
The docs follow Home Assistant's development branch, not the pinned version. A page can describe an API that
arrives only in the next release — check that it exists in the installed source before using it; if it does not,
it is upcoming and needs the minimum version in hacs.json raised first.
The same rule, generalised: what counts as verified
This applies to any API, tool or configuration key you are about to commit to. Only a primary source settles a question — the installed source you import, or the current documentation of the tool you are configuring. A GitHub issue, a blog post, another tool's convention and your own recall are leads, never answers.
Two traps make a secondary source feel primary:
- Silent failure. Most configuration rejects nothing: an unknown key is ignored, and the resulting default often looks like success. Before believing "X works", ask what a broken X would look like — if the answer is "the same thing", the observation proved nothing. Test the case that can fail: the file that should not match, the entry that should not load.
- A key that belongs to a neighbouring tool. Copilot, Cursor and Claude Code each name the same idea differently
(
applyTo,globs,paths). That a key works in one tool is no evidence for the next, and the wrong one will not complain.
When you deviate from documented behaviour, the bar is: name the primary source you checked, and design an observation
that could have come out the other way. If neither is possible, follow the documentation and say you could not verify
it. When the answer matters enough to encode, put a check in script/ rather than a comment.
Reference files
| File | When to read |
|---|---|
references/deprecations.md |
Fixing a specific deprecation. "Do not use → use instead" tables with the removal version — moved imports, config entry setup, config flow, entities and per-platform changes, actions and conditions, async and I/O, recorder statistics, upcoming changes. |
references/device-registry.md |
Anything that registers, looks up, links or removes a device: single ownership, scoped lookups, via_device_id versus child devices, helper entities, and the device registry deprecations with their removal versions. |
Read it when you have a concrete symbol to replace — do not pull it into context speculatively.
The three that matter most in this codebase
1. Device registry single ownership. A device belongs to exactly one config entry and at most one subentry. Identifiers are unique only within their owning entry. Always scope lookups:
device = device_registry.async_get_device_by_identifier((DOMAIN, serial), entry.entry_id)
Never the unscoped async_get_device() — it is deprecated, and with two entries sharing an
identifier it resolves ambiguously. Parts of one product are child devices, not via_device_id devices —
references/device-registry.md.
2. Typed runtime_data. State belongs on the entry, not in hass.data:
type {ClassPrefix}ConfigEntry = ConfigEntry[{ClassPrefix}Data]
entry.runtime_data = {ClassPrefix}Data(client=client, coordinator=coordinator, integration=integration)
3. Tests catch Home Assistant's deprecations through a fixture, not through warnings — see
ha-testing. Fix the deprecation; never filter it.
Fixing a deprecation warning
- Read the log line — it names the symbol, and usually the replacement and the removal version.
- Confirm the replacement's real signature in the installed source. Signatures shift between the announcement and the release.
- Replace every occurrence, including tests, diagnostics, repairs, and migrations. A half-migrated codebase is worse than an un-migrated one.
script/lint && script/type-check && script/test. For a path no test reaches, restart Home Assistant, exercise it, and confirm the line is gone — many are logged only once per run, and only when the code runs:rg -n "Detected that custom integration|The deprecated .* from <domain>" config/home-assistant.log.
Bumping the Home Assistant version
script/ha-version-sync # keeps hacs.json, .devcontainer/.env and friends aligned
Then rebuild the container (or re-run script/setup/bootstrap), and:
script/hassfest && script/test
rg -n "Detected that custom integration|The deprecated|DeprecationWarning|will be removed" config/home-assistant.log
When script/test reports that the manifest schema's categories differ from the installed Home Assistant, run
python3 script/.lib/manifest_categories.py in the project virtualenv to copy them over.
Raising the minimum version is a separate decision:
ha-marketplace for where it lives,
ha-breaking-changes for why it is breaking.
Do not
- Do not "fix" a deprecation by suppressing the warning.
- Do not trust an example from an older Home Assistant release, a Stack Overflow answer, or your own recall without checking the installed source first.
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.