fix(debug): let Companion-app users get a debug snapshot without a browser - #4743
Open
chalfontchubby wants to merge 3 commits into
Open
fix(debug): let Companion-app users get a debug snapshot without a browser#4743chalfontchubby wants to merge 3 commits into
chalfontchubby wants to merge 3 commits into
Conversation
…owser The HA Companion app's embedded webview ignores Content-Disposition: attachment, so the Debug panel's tgz/single-file downloads just render inline instead of saving - there's no server-side fix for that. Every rolling debug-history snapshot is now written straight to config_root/debug/ (the same directory switch.predbat_debug_enable already uses), so it's reachable with File Editor/Samba instead. The dashboard and docs now say so, and an install upgrading from before this change still has its existing snapshots readable (and eventually cleaned up) via a legacy-key fallback. Fixes #4720
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Failed debug-file writes are currently recorded as successful captures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Moves rolling debug snapshots into config_root/debug/ so Companion-app users can access them via File Editor or Samba.
Changes:
- Adds debug-file operations to the storage abstraction.
- Preserves legacy cached snapshots during upgrades.
- Updates dashboard guidance, documentation, and tests.
File summaries
| File | Description |
|---|---|
docs/customisation.md |
Documents Companion-app workaround and snapshot location. |
apps/predbat/web.py |
Adds dashboard guidance. |
apps/predbat/storage.py |
Implements debug-directory storage operations. |
apps/predbat/debug_history.py |
Stores snapshots in debug/ with legacy fallback. |
apps/predbat/tests/test_web_functions.py |
Tests dashboard guidance. |
apps/predbat/tests/test_storage.py |
Tests debug-file operations. |
apps/predbat/tests/test_debug_history.py |
Tests retention and migration behavior. |
apps/predbat/tests/test_debug_history_capture.py |
Verifies snapshots are written to debug/. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
capture_snapshot() lost the leading indent on `filename = snapshot_filename(...)` in 349b527 ("Apply suggestions from code review"), leaving it at column 0 inside the function body - a syntax error ruff/black correctly rejected. Co-Authored-By: Claude Opus 5 <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.
Summary
Content-Disposition: attachment, so the Debug panel's.tgz/single-file download links just render the content inline instead of saving it - a client-side limitation with no server fix, discussed in Rolling debug logs not accessible with HA Companion app #4720.config_root/debug/- the same directoryswitch.predbat_debug_enablealready uses - via newsave_debug_copy()/load_debug_copy()/delete_debug_copy()methods on the Storage abstraction, so a Companion-app user can grab one with File Editor/Samba instead of the browser-only download routes.docs/customisation.mdnow say so.Note on storage layout
cache/is generally the right place for cache-like, regenerable data, and this PR deliberately doesn't put snapshot content there - it goes straight todebug/, with only the small index staying incache/. That's a pragmatic workaround for this specific problem (a real file on disk is what makes it reachable from the Companion app at all), not a new general pattern - it works here becausecreate_debug_yaml()already writes unconditionally to that same real directory forswitch.predbat_debug_enable, so nothing here is any more filesystem-dependent than the feature it's capturing snapshots of.Test plan
./run_pre_commit(ruff, black, cspell, markdownlint, interrogate 100% on touched files) - green./run_all --quick- green, including new tests for: the debug/ write/read/delete path, the pre-Rolling debug logs not accessible with HA Companion app #4720 legacy-key fallback (read) and reap (on eviction) on a real Storage backend, and the dashboard's Companion-app caveat textFixes #4720