Conversation
There was a problem hiding this comment.
Pull request overview
Adds a persistent boot counter to SteamiConfig (stored in the DAPLink config zone JSON) to track device power cycles for diagnostics and usage tracking.
Changes:
- Add
set_boot_count(),get_boot_count(), andincrement_boot_count()toSteamiConfig. - Extend mock + hardware scenario coverage for boot counter persistence/coexistence.
- Update
steami_configREADME and add a newboot_counter.pyexample.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lib/steami_config/steami_config/device.py |
Implements the boot counter API on top of existing JSON persistence. |
tests/scenarios/steami_config.yaml |
Adds mock and hardware scenario scripts for set/get/increment and persistence/coexistence. |
lib/steami_config/README.md |
Documents the new boot counter feature and updates the JSON schema + examples list. |
lib/steami_config/examples/boot_counter.py |
Provides a startup-time example that increments and saves the boot counter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| config.get_boot_count() | ||
| print("Boot count:", count) |
There was a problem hiding this comment.
The “Get boot counter” README snippet calls config.get_boot_count() but then prints count, which is never assigned. Assign the return value to count (and consider showing the None case since get_boot_count() can return None when unset).
| config.get_boot_count() | |
| print("Boot count:", count) | |
| count = config.get_boot_count() | |
| if count is None: | |
| print("Boot count is not set") | |
| else: | |
| print("Boot count:", count) |
There was a problem hiding this comment.
Fixed in 05a5d81: added count = before config.get_boot_count().
| ## Boot counter | ||
| Store and restore amount of boot of the card. | ||
|
|
||
| ### Set boot counter |
There was a problem hiding this comment.
The new Boot counter section wording is unclear/incorrect (“amount of boot of the card”) and has trailing spaces in headings. Please rephrase to clearly describe the board boot count (e.g., “number of board boots/power cycles”) and remove the trailing whitespace.
There was a problem hiding this comment.
Fixed in 369cd25: reworded to "Track how many times the board has booted." and removed trailing spaces.
| | `cm.sx/sy/sz` | Soft-iron scale factors (X, Y, Z) | | ||
| | `ca` | Accelerometer calibration dict | | ||
| | `ca.ox/oy/oz` | Bias offsets in g (X, Y, Z) | | ||
| | `boot_count` | Count of the amount of boot | |
There was a problem hiding this comment.
The JSON key description for boot_count (“Count of the amount of boot”) is grammatically incorrect/unclear. Please update this table entry to something unambiguous like “Boot count (number of power cycles)”.
| | `boot_count` | Count of the amount of boot | | |
| | `boot_count` | Boot count (number of power cycles) | |
There was a problem hiding this comment.
Fixed in 95a2d36: key renamed to "bc" and table entry updated to "Boot counter".
| # --- Boot counter logic --- | ||
| config.increment_boot_count() | ||
|
|
||
| # Save updated value | ||
| config.save() |
There was a problem hiding this comment.
This example increments the counter and immediately calls config.save(). Since SteamiConfig.save() erases the config zone (bridge.clear_config()) before rewriting JSON, doing this on every boot can significantly increase flash erase/write cycles (and is especially risky in reboot loops). Consider adding a note about flash wear / optionally persisting less frequently (e.g., only every N boots or on graceful shutdown).
There was a problem hiding this comment.
Valid point about flash wear. However, this is a pedagogical example — simplicity is the priority. The STeaMi DAPLink config zone uses a dedicated EEPROM-like region, not the main flash, so the write endurance is higher. Adding wear-leveling logic to a 28-line example would obscure the intent. A comment warning about frequent writes could be added, but it's not blocking.
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| # -- Hardware Boot Counter -- |
There was a problem hiding this comment.
The “Hardware Boot Counter” section header comment is indented under the previous test case (same indentation as mode:), which makes the YAML harder to scan. Align this comment with the other section headers at the list indentation level for consistency/readability.
| # -- Hardware Boot Counter -- | |
| # -- Hardware Boot Counter -- |
There was a problem hiding this comment.
Fixed in 591af42: comment realigned from 4 spaces to 2 spaces, consistent with all other section headers.
Review & corrections appliedWhat was reviewedGood PR — code is simple, well-tested (6 mock + 4 hardware), and the example is clear. A few issues were found and corrected directly on the branch. Corrections applied
Not changed
StatusAll 5 Copilot comments addressed. 46 mock tests pass. Ready to merge (squash recommended to clean up the 9-commit history). |
|
🎉 This PR is included in version 0.12.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Summary
Closes #172
Add support for a persistent boot counter in
SteamiConfigto track the number of power cycles. This is useful for diagnostics, debugging reboot loops, and usage tracking.The boot count is stored in the config zone using a compact JSON format:
{"boot_count": 427}Part of #166
Depends on #167 (config zone driver methods)
Changes
Add
set_boot_count(count)method to store boot countAdd
get_boot_count()method to retrieve boot countAdd
increment_boot_count()helper to safely increment the counterStore boot counter in config JSON under
"boot_count"Ensure safe behavior when value is missing (defaults to 0 on increment)
Add example demonstrating boot counter usage at startup
Add mock tests:
Add hardware tests:
Checklist
ruff checkpassespython -m pytest tests/ -k mock -vpasses (no mock test broken)<scope>: <Description.>format