Add auto-update for missing configuration settings

Implemented automatic config file updates to add missing settings
with default values on startup. This eliminates manual config
editing when upgrading to newer versions.

Features:
- Auto-updates config.json with missing settings
- Auto-updates user_config.json with missing user preferences
- Console logging shows which settings were added
- Preserves existing values - only adds missing keys
- Writes updated config back to file automatically
- Graceful error handling if write fails

System config (config.json):
- Comprehensive defaults for all sections
- GPIO, audio, paths, backup, web, system settings
- New settings like volume_greeting, volume_button, volume_beep

User config (user_config.json):
- Loop-based checking against default_config
- Automatic save when updates are detected
- Error logging for troubleshooting

Benefits:
- Seamless upgrades without manual config edits
- No breaking changes when new features are added
- Users see exactly what was added in console
- Backward compatible with old config files

Example console output:
  [CONFIG] Added missing setting: system.volume_beep = 70
  [CONFIG] Updated config.json with missing defaults
  [USER_CONFIG] Added missing setting: volume_button = 70
  [USER_CONFIG] Updated user_config.json with missing defaults

Updated README.md to document auto-update feature.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-27 16:02:50 +07:00
parent b219619f24
commit 1b1a40b094
2 changed files with 104 additions and 18 deletions

View File

@@ -491,6 +491,18 @@ rotary_phone_data/ # Default location (configurable)
All configuration is done via the `config.json` file. **No need to edit Python code!**
### Auto-Update Feature
The system automatically adds missing configuration settings with default values when it starts:
- **config.json** - System configuration is auto-updated with any missing settings
- **user_config.json** - User settings are auto-updated with new defaults
- Console shows which settings were added: `[CONFIG] Added missing setting: system.volume_beep = 70`
- Original config is preserved - only missing keys are added
- No manual editing required when upgrading to newer versions
This means you can upgrade the code and your old config files will work automatically!
### Configuration File Structure
The `config.json` file contains all system settings: