Read the encryption key from the esphome OTA platform and rename the command - #2679
Conversation
…command esphome 2026.9 shares one Noise key between the native API and the esphome OTA platform, so the key can live under either block. Resolve it from api: first and fall back to the OTA item's own key, expose whether the OTA item declares encryption as Device.ota_encryption_required, and rename devices/get_api_key to devices/get_encryption_key.
|
@esphbot review |
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
=======================================
Coverage 99.73% 99.73%
=======================================
Files 282 282
Lines 24067 24073 +6
=======================================
+ Hits 24003 24010 +7
+ Misses 64 63 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@esphbot review |
There was a problem hiding this comment.
🟡 Changes recommended
ota_encryption_required can be incorrectly set because the raw-YAML OTA heuristic is applied even when a parsed config is available, potentially flagging non-esphome OTA platform entries.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the device encryption-key resolution to match ESPHome 2026.9’s “single Noise key” behavior by (1) falling back to the ESPHome OTA platform’s encryption key when api.encryption.key is absent and (2) renaming the WS command from devices/get_api_key to devices/get_encryption_key, while also exposing an ota_encryption_required flag on Device for UI gating.
Changes:
- Add OTA-encryption parsing + resolution helpers and a
Device.ota_encryption_requiredflag (raw-YAML heuristic + resolved-config path). - Rename the devices-controller WS command to
devices/get_encryption_keyand route it through the new “api-else-ota” resolver. - Update tests and API documentation to reflect the new command name and OTA fallback behavior.
File summaries
| File | Description |
|---|---|
| tests/test_run_esphome_config.py | Updates test module docs to reference devices/get_encryption_key fallback. |
| tests/test_api_key.py | Adds helper/unit tests for OTA encryption extraction and resolved “one key” behavior; adds scanner tests for ota_encryption_required. |
| tests/controllers/devices/test_branches_coverage.py | Renames controller wiring tests to get_encryption_key and adds coverage for OTA-only configs. |
| esphome_device_builder/models/devices.py | Adds Device.ota_encryption_required field for UI gating of “Show encryption key”. |
| esphome_device_builder/helpers/device_yaml/_parsing.py | Adds raw-YAML OTA encryption heuristic and OTA encryption extraction/resolution helpers. |
| esphome_device_builder/helpers/device_yaml/_loading.py | Populates ota_encryption_required during device scan/load. |
| esphome_device_builder/helpers/device_yaml/init.py | Re-exports the new OTA/encryption-key helpers. |
| esphome_device_builder/controllers/devices/controller.py | Renames the WS command handler to devices/get_encryption_key. |
| esphome_device_builder/controllers/devices/api_key.py | Updates controller helper to resolve “api key else OTA key”, including subprocess fallback. |
| esphome_device_builder/controllers/devices/init.py | Updates module docs to reflect broader responsibilities of api_key. |
| docs/API.md | Documents new devices/get_encryption_key command and Device.ota_encryption_required. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@esphbot review |
There was a problem hiding this comment.
🔵 Needs a closer look
The new get_resolved_encryption_key() precedence can incorrectly fall back to the OTA key even when an api.encryption block exists but its key is unresolved/invalid, which contradicts the documented “api first, else OTA” rule.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
esphome_device_builder/helpers/device_yaml/_parsing.py:895
get_resolved_encryption_key()currently falls back to the OTA key whenever the resolved API key is empty, which also happens when anapi.encryptionblock exists but its key is unresolved/invalid (e.g.${...}still present). That can make the OTA key “win” even though the API encryption block is present and should be authoritative per the documented precedence (api key first, else OTA key). Consider only falling back to the OTA key when theapi.encryptionblock is absent, not merely when the API key resolves to an empty string.
- Files reviewed: 11/11 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
On the |
Agreed — precedence reasoning holds, and preferring api with an OTA fallback matches esphome's own equality constraint. One adjacent gap, separate from precedence: bare Benign in practice — a bare block only compiles alongside an api key, which already sets |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
Addressed in e4d51d5: |
|
@esphbot review |
A bare encryption: parses to None, so the flag is a presence check on the esphome OTA entry; the own-key helper scans every esphome entry again.
3f836a5 to
e4d51d5
Compare
|
@esphbot review |
|
@esphbot review |
…ex factory Drop the callerless block getter and the own-key alias, share the raw regex factory with the api heuristic, route the partition-access walker through the same entry helper, and fold the resolved-or-raw choice into a helper shaped like its mdns and mac-suffix siblings.
|
@esphbot review |
Confirmed, all three resolved.
One remaining note: |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
On |
|
@esphbot review |
Agreed, dropping that note. Verified |
PR Review — Read the encryption key from the esphome OTA platform and rename the commandMerge-ready. Every prior finding — mine and Copilot's — is genuinely fixed, and the follow-up commits shrank the change rather than patching over it. One non-blocking merge-ordering note. Specific things done well:
Checklist
Automated review by Kōan (Claude) |
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
What does this implement/fix?
esphome 2026.9 uses one Noise key for both the native API and the esphome OTA platform: an explicit OTA key must equal the api key, a bare
ota: encryption:inherits it, and a device with noapi:block can still carry the key underota:. The key lookup now resolvesapi: encryption: keyfirst and falls back to the esphome OTA item's own key,Devicegainsota_encryption_requiredso the dashboard can offer the key for an OTA only device, anddevices/get_api_keyis renamed todevices/get_encryption_key; the reply shape is unchanged.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.