Isolate aiohttp session and storage per config entry (multi-account support) - #4
Merged
Merged
Conversation
Multiple BoilerJuice accounts were overwriting each other because the coordinator used Home Assistant's shared aiohttp session (and therefore a shared cookie jar), and the consumption store fell back to a single "default" bucket when no tank id was configured. Each coordinator now owns a private ClientSession with its own CookieJar, and consumption data is keyed by config entry id with a migration path from legacy tank-id keys. Also: - Close the private session on entry unload and after config-flow validation so temporary coordinators don't leak connections. - Add optional device_id/entry_id target selectors to the reset_consumption and set_consumption services so they no longer fan out to every configured account. - Remove a stray reset_consumption registration in sensor.py that shadowed the properly-schemaed service with a single-coordinator one, and make async_unload_services drop set_consumption too.
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
aiohttp.ClientSessionwith a dedicatedCookieJarso two BoilerJuice accounts can't overwrite each other's login cookies (root cause reported in Support for multiple instances? #3).entry_idinstead of tank id, with a migration path from existing tank-id and"default"keys so nobody loses history on upgrade. The shared"default"bucket is left in place to avoid a race between two entries migrating from it.reset_consumptionandset_consumptionnow accept optionaldevice_id/entry_id(plus the normal HA target selector) and only hit the matching coordinator(s). When nothing is selected the old "apply to all" behaviour is preserved for backwards compatibility.async_unload_entryand on config-flow validation, so failed logins don't leak a connection.reset_consumptionregistration insensor.pythat had no schema and closed over a single coordinator, shadowing the real service.async_unload_servicesnow also removesset_consumption.manifest.jsonto1.2.0.Related to #3 (leaving the issue open for discussion with the reporter).
Test plan
black --check custom_components/boilerjuice/isort --check-only custom_components/boilerjuice/flake8 custom_components/boilerjuice/ --select=E9,F63,F7,F82(strict CI checks)_resolve_target_coordinatorswith stubbed HA internals: no-target,entry_id, single/multidevice_id, and unknown-target error paths.Store: legacy tank-id keys migrate into per-entry keys, shared"default"bucket is preserved when multiple entries might still need it, and the no-entry validation path falls back safely.boilerjuice.reset_consumptiontargeted at a single device and confirm the other account is untouched.