fix(tanks): seed tankVolume2 capacity from the data tree#266
Open
msallin wants to merge 2 commits into
Open
Conversation
When a tank's capacity comes from defaults.json, the streambundle applies it at server boot but doesn't replay the delta to plugins that subscribe later. The combined stream over [currentLevel, capacity] blocks forever waiting on capacity and no currentVolume emits. Read capacity once via app.getSelfPath at factory time (after plugin.start, so defaults are already in the tree) and seed the capacity slot via the `defaults` array already consumed by index.ts. Bacon's toProperty semantics let a real streamed capacity delta supersede the seed, so tank senders still work unchanged. Also tightens the input guards to reject negative, zero, and non-finite capacities (so a misconfigured defaults.json doesn't emit nonsense volumes), aligns the title format with tankVolume.ts, and adds an integration test that pushes only currentLevel against a seeded capacity to pin the regression.
Keep the two real-world cases the seed covers (defaults.json static capacity, and a tank sender's streamed capacity) and drop the implementation walkthrough.
Collaborator
Author
|
@tkurki may I have your opinion here? My case is that the tank capacity comes from defaults.json. |
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
tankVolume2never emittingcurrentVolumewhencapacitycomes fromdefaults.json(or any static source that doesn't push deltas through the streambundle to late subscribers).app.getSelfPathat factory time via the existingdefaultsarray; streamed capacity from a tank sender still supersedes the seed.Number.isFinite(x) && x > 0) so a misconfigured negative or zero capacity doesn't emit nonsense volumes.Why
The
signalk-serverstreambundle appliesdefaults.jsonvalues at server boot but does not replay those deltas to plugins that subscribe later.tankVolume2uses Bacon'scombineover[currentLevel, capacity], so a defaults-only capacity leaves the combined stream blocked forever waiting on a capacity delta that never arrives. Users see the checkbox enabled in the plugin config but no output for the tank.The plugin's calculation framework already supports per-input seeding via the optional
defaultsarray on aCalculation(consumed insrc/index.tsvia Bacon's.toProperty(seed)); eight other calcs already use it. This change adopts the same mechanism for capacity, with the seed read from the data tree at start. Bacon'stoPropertysemantics let any subsequent real capacity delta override the seed, so tank-sender plugins and mid-runtime recalibration paths are preserved.Title also cleaned up: dropped the dangling "Uses " fragment that was clearly a truncated template, and aligned the format with
tankVolume.ts.Test plan
npm test— 323 passing (was 319; +4 new tests: 2 unit boundary cases incl. the multi-tank seeding regression, 2 integration tests covering the seeded-from-tree and streamed-capacity paths).npm run typecheck— clean.npm run prettier:check— clean.defaults.json: confirmtanks.<inst>.currentVolumestarts emitting on the nextcurrentLeveldelta after enablingtankVolume2.