Skip to content

fix(admin): keep dashboard toggles in the state directory - #310

Open
diferhe wants to merge 5 commits into
Python-roborock:mainfrom
diferhe:fix/admin-toggle-state
Open

diferhe wants to merge 5 commits into
Python-roborock:mainfrom
diferhe:fix/admin-toggle-state

Conversation

@diferhe

@diferhe diferhe commented Nov 29, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #196.

When an admin turns Protocol auth or New connections on or off in the dashboard, the server used to rewrite config.toml in place. That causes three problems:

  • Fails on Docker Compose: the shipped compose.yaml mounts config.toml read-only, so the toggle returns HTTP 500 with [Errno 30] Read-only file system: '/app/config.toml' and the setting does not change.
  • Lost on add-on restart: the Home Assistant add-on regenerates config.toml from its options on every start, and always writes both settings as true. Turning off new connections in the dashboard was therefore undone by the next add-on restart.
  • Not atomic: a crash during the rewrite could leave a truncated config.toml.

Dashboard changes are now stored in state/admin_settings.json in the data directory, and config.toml is never written by the server.

  • Defaults: the config file still provides the defaults.
  • Precedence: each stored value remembers the config value it overrode. While the config keeps that value, the dashboard change stays in effect, also across restarts. When the config value changes, the config wins and the stored value is discarded. So a later edit of the config file replaces an earlier dashboard change.
  • Durable writes: the file is written to a temporary file, synced, renamed into place, and the directory is synced, so a power failure cannot undo a change.
  • Invalid file: an invalid settings file stops the server with an error naming the file, instead of silently falling back to the config and reopening access.

Existing installs need no migration. Their current config values remain the defaults. This also covers configs generated on every start, such as the environment-variable config proposed in #176.

Before you open this PR (optional, but very helpful)

PRs I reviewed:

Proof that it works

Tested on:

  • Vacuum model: not tested on a vacuum (admin API only)
  • Firmware version: n/a
  • Server version / commit: 83128b2
  • Install method (Docker / Home Assistant add-on / other): unit tests

What I did and what happened:

New tests:

  • tests/test_admin_api.py:
    • both toggles work through the admin API when config.toml and its directory are read-only, as with the :ro mount in compose.yaml. The config stays byte-for-byte unchanged and both changes survive a restart. Without this fix, the same test fails with HTTP 500.
    • toggles survive a restart and config.toml is left unchanged. This replaces the two tests of the old in-place rewrite.
  • tests/test_admin_settings.py:
    • stored values and the precedence rule
    • stale values discarded after a config change
    • invalid files rejected
    • the order of the write and sync calls
    • a failed directory sync keeping memory and file consistent
  • tests/test_ha_addon.py: both toggles survive the add-on regenerating config.toml from its options.

uv run pytest -q passes in full.

Screenshots (required for any UI change)

No UI changes. The dashboard behaves the same, except that the toggles now work with the shipped compose.yaml and survive restarts of the Home Assistant add-on.

The admin dashboard used to rewrite config.toml in place when an admin
turned protocol auth or new connections on or off. That write was not
atomic, failed for read-only config files, and was undone on every restart
of the Home Assistant add-on, which regenerates config.toml from its options.

Dashboard changes are now stored atomically in state/admin_settings.json.
The config file provides the default, and a stored value is discarded once
the config value it overrode changes, so the most recent change wins. An
invalid settings file stops the server with a clear error instead of
silently reopening access.
Also describe the precedence rule of stored dashboard settings precisely.
Without syncing the directory, a power failure right after a change could
bring back the previous file and silently undo a restriction.
The shipped compose.yaml mounts config.toml read-only, which made the
toggles fail with HTTP 500 before the settings moved to the state
directory.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin UI toggles fail with [Errno 30] Read-only file system: '/app/config.toml' on the shipped compose.yaml

1 participant