Skip to content

dbushelper: centralize Victron settings bus name; clarify get_bus#433

Open
cgoudie wants to merge 5 commits intomr-manuel:masterfrom
TechBlueprints:chore/dbus-get-bus-hygiene
Open

dbushelper: centralize Victron settings bus name; clarify get_bus#433
cgoudie wants to merge 5 commits intomr-manuel:masterfrom
TechBlueprints:chore/dbus-get-bus-hygiene

Conversation

@cgoudie
Copy link
Copy Markdown
Contributor

@cgoudie cgoudie commented Apr 7, 2026

Summary

Follow-up after per-service get_bus(dbus_name) (issue #410, PR #402):

  • Add VICTRON_SETTINGS_DBUS_NAME so com.victronenergy.settings is not repeated across every get_bus / settings helper call (same string is both the connection cache key and the D-Bus service name Victron’s settings daemon uses).
  • Type-hint get_bus(dbus_name: str) and expand the docstring: D-Bus spec well-known name, when the settings name is intentionally shared across all helpers vs when each battery needs a distinct _dbusname / connection.
  • Fix a comment typo (preareprepare).

No runtime behaviour change.

Does not address issue #417 (stale SOC / duplicate device entries); that is PR #429.

Coordination with PR #429

PR #429 also edits dbus-serialbattery/dbushelper.py (save_current_battery_state, save cadence, duplicate UniqueIdentifier handling). Merge order only needs a small mechanical follow-up:

Optional: I can push a commit to the #429 branch with only those substitutions if that helps.

@mr-manuel @lex2k0

Cross-links

Pointers to this PR were added in: #410 (comment), #417 (comment), #429 (comment), #402 (comment).

Clinton Goudie-Nice added 3 commits April 7, 2026 18:20
- Add VICTRON_SETTINGS_DBUS_NAME as single source for the Victron settings
  well-known name, used both as get_bus() cache key and as the service
  argument to settings helpers (DRY, typo-resistant).
- Annotate get_bus(dbus_name: str) and clarify that dbus_name is the
  _bus_instances key and typically the peer well-known name.
- Fix comment typo (preare -> prepare).

Refs: mr-manuel#410
Related: mr-manuel#402
Made-with: Cursor
Clinton Goudie-Nice added 2 commits April 7, 2026 18:29
…el#402)

- Stub BusConnection.get_is_connected in conftest so get_bus() works under tests.
- Assert same key reuses connection, distinct battery names differ, settings
  share VICTRON_SETTINGS_DBUS_NAME cache entry separate from battery names.

Made-with: Cursor
…uel#402)

Patch SystemBus/SessionBus and count constructors: many calls with the same
cache key must yield one allocation; N keys → N allocations. Covers reconnect
when get_is_connected is false.

Made-with: Cursor
@cgoudie
Copy link
Copy Markdown
Contributor Author

cgoudie commented Apr 7, 2026

Merge / dependency reminder: The `get_bus(dbus_name)` keyed cache (per battery `_dbusname` + shared settings name) is required for issue #410 alongside the leak fix in PR #402. This PR documents and tests that design but does not introduce it — ensure `master` already has (or merges together with) the per-name behaviour, not a single global bus for all `VeDbusService` instances.

See new comments on #410 and #402 for the same note.

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