Add JSON serialization support for companion preferences

- Introduced a new utility function, _to_json_safe, to ensure companion preferences are JSON-serializable, handling various data types including enums and dataclasses.
- Updated the RepeaterCompanionBridge to use the new serialization method when saving preferences to SQLite.
- Modified SQLiteHandler to ensure companion_hash is consistently converted to a string before database operations.
- Enhanced error handling for preference persistence in the RepeaterCompanionBridge.
This commit is contained in:
agessaman
2026-03-03 16:20:52 -08:00
parent 4f94b343cc
commit 1fbd99d52c
2 changed files with 24 additions and 2 deletions
+2 -1
View File
@@ -1833,6 +1833,7 @@ class SQLiteHandler:
"""Persist prefs for a companion as JSON. Upserts by companion_hash."""
try:
prefs_json = json.dumps(prefs)
key = str(companion_hash) if companion_hash is not None else ""
with sqlite3.connect(self.sqlite_path) as conn:
conn.execute(
"""
@@ -1840,7 +1841,7 @@ class SQLiteHandler:
VALUES (?, ?)
ON CONFLICT(companion_hash) DO UPDATE SET prefs_json = excluded.prefs_json
""",
(companion_hash, prefs_json),
(key, prefs_json),
)
conn.commit()
return True