Skip to content

Normalise settings on a fresh install (Vehicles page and VIN check crash without settings.json) - #758

Open
MikeBishop wants to merge 2 commits into
ngardiner:mainfrom
MikeBishop:fix/fresh-install-settings
Open

MikeBishop wants to merge 2 commits into
ngardiner:mainfrom
MikeBishop:fix/fresh-install-settings

Conversation

@MikeBishop

Copy link
Copy Markdown
Collaborator

Problem

On a fresh install with no settings.json yet, TWCMaster.loadSettings() fills in the defaults and then returns early. Everything after the file read gets skipped, including creating the built-in Allow Charging / Deny Charging vehicle groups. Two things depend on those groups existing:

  • Vehicles page: vehicles.html.j2 loops over master.settings["VehicleGroups"].keys(), and the page fails with
    jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'VehicleGroups'.
  • VIN entitlement: checkVINEntitlement() reads self.settings["VehicleGroups"][...] directly and raises KeyError as soon as a TWC reports a VIN. This happens even in the default authorization mode (1).

The early return also skips the vehicle registry, held-limit, watch-budget and fleet-spend loads, token restore, the sunrise/sunset defaults, and each vehicle module's updateSettings().

The problem clears on the first restart after settings.json has been written, because loading an existing file does create the groups. That's probably why it has gone unnoticed.

How far back

  • The early return has been there since settings.json was introduced (da3a8d4, Oct 2019). It was harmless until code started relying on the groups.
  • Both crashes arrived in v1.2.2 (Apr 2021): the template loop in 790c590 and the entitlement check in 5c737e2.
  • Every release from v1.2.2 through v1.4.0, and current main, is affected.

Fix

A missing settings file is now treated as an empty settings dict and goes through the same steps as a loaded file. A fresh install ends up with exactly the settings an empty settings.json would give.

Tests

New tests/unit/test_fresh_install_settings.py, run with no settings.json:

  • the built-in groups and the sunrise/sunset defaults are present
  • the loaded settings are identical to those from an empty settings.json
  • the Vehicles page renders
  • checkVINEntitlement() returns 1 instead of raising

All four fail on current main and pass with this change. The full unit suite passes (2660 tests).

🤖 Generated with Claude Code

root and others added 2 commits November 9, 2026 04:13
loadSettings returned early when settings.json did not exist, skipping
everything after the file read: the built-in Allow/Deny Charging vehicle
groups, the sunrise/sunset bridge values, the registry/held-limit/budget
loads, token restore, and module updateSettings.

Without VehicleGroups, the Vehicles page raised UndefinedError and
checkVINEntitlement raised KeyError as soon as a car reported a VIN.
Both have depended on that key since v1.2.2 (790c590, 5c737e2); the
early return dates to the settings.json format itself (da3a8d4). The
condition clears on the first restart after settings.json is written.

A missing file now falls through as an empty dict, so a fresh install
gets exactly the settings an empty settings.json would.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant