Repository navigation
fix(web): the Charge now slider stops at the most Core can order #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
frahlg
wants to merge
1
commit into
master
Choose a base branch
from
fix/charge-now-slider-steps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ftw": patch | ||
| --- | ||
|
|
||
| The Charge now slider in the EV charger dialog now stops at the most FTW can order. It took its top from the charger's maximum, so a 32 A one-phase charger whose levels stop at 3.7 kW read 6–32 A, "32 A · 7.4 kW" and "FTW received 32 A" while FTW charged at 16 A. When a charger has a list of levels, the top is now the highest level at or below its maximum: 16 A · 3.7 kW for that charger. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import test from 'node:test'; | ||
|
|
||
| const source = readFileSync(new URL('./app.js', import.meta.url), 'utf8'); | ||
| const section = source.slice( | ||
| source.indexOf('function evIsPaused'), | ||
| source.indexOf('function sliderHeader'), | ||
| ); | ||
|
|
||
| // Core treats a Charge now hold as a ceiling and floors it to the charger's | ||
| // step table within max_charge_w. The slider must stop where Core does: a | ||
| // one-phase charger rated 32 A with a 16 A table showed 6–32 A and | ||
| // "32 A · 7.4 kW" while Core ordered 3,680 W (22 Oct 2026 rig). | ||
|
|
||
| class FakeEl { | ||
| constructor(tag) { | ||
| this.tagName = tag.toUpperCase(); | ||
| this.style = {}; | ||
| this.children = []; | ||
| this.attributes = {}; | ||
| this.listeners = {}; | ||
| this.textContent = ''; | ||
| } | ||
| setAttribute(k, v) { this.attributes[k] = String(v); } | ||
| appendChild(c) { this.children.push(c); return c; } | ||
| addEventListener(type, fn) { (this.listeners[type] ||= []).push(fn); } | ||
| cloneNode() { const c = new FakeEl(this.tagName); Object.assign(c.style, this.style); return c; } | ||
| fire(type) { for (const fn of this.listeners[type] || []) fn({ type }); } | ||
| } | ||
|
|
||
| function walk(el, out = []) { | ||
| out.push(el); | ||
| for (const c of el.children) walk(c, out); | ||
| return out; | ||
| } | ||
|
|
||
| function build(lp) { | ||
| const sent = []; | ||
| const evWrite = (path, opts) => { sent.push(JSON.parse(opts.body)); return new Promise(() => {}); }; | ||
| const make = new Function('document', 'evWrite', 'refreshEvModalAfterWrite', section + '; return buildManualChargeSection;'); | ||
| const ctl = make({ createElement: tag => new FakeEl(tag) }, evWrite, () => {})(lp); | ||
| const all = walk(ctl.el); | ||
| const slider = all.find(el => el.tagName === 'INPUT' && el.type === 'range'); | ||
| const row = all.find(el => el.children.includes(slider)); | ||
| return { | ||
| slider, | ||
| readout: row.children[1], | ||
| status: all.find(el => el.tagName === 'SMALL'), | ||
| start: all.find(el => el.tagName === 'BUTTON' && el.textContent === 'Charge now'), | ||
| sent, | ||
| }; | ||
| } | ||
|
|
||
| const onePhase = { | ||
| id: 'garage', phases: 1, voltage_v: 230, plugged_in: true, | ||
| min_charge_w: 1380, max_charge_w: 7360, allowed_steps_w: [0, 1380, 2300, 3680], | ||
| }; | ||
|
|
||
| test('a one-phase charger tops out at the top of its step table', () => { | ||
| const ui = build(onePhase); | ||
| assert.equal(ui.slider.min, '6'); | ||
| assert.equal(ui.slider.max, '16'); | ||
| assert.equal(ui.readout.textContent, '16 A · 3.7 kW'); | ||
| assert.match(ui.status.textContent, /^Starts at up to 16 A · 3\.7 kW\./); | ||
| ui.start.fire('click'); | ||
| assert.deepEqual(ui.sent, [{ power_w: 3680, hold_s: 0, phase_mode: '1p' }]); | ||
| }); | ||
|
|
||
| test('a hold above the table reads as the top Core can order', () => { | ||
| const ui = build({ ...onePhase, manual_active: true, manual_charge_w: 7360 }); | ||
| assert.equal(ui.slider.value, '16'); | ||
| assert.equal(ui.readout.textContent, '16 A · 3.7 kW'); | ||
| }); | ||
|
|
||
| test('the top is the highest step within max_charge_w', () => { | ||
| const ui = build({ | ||
| id: 'garage', phases: 3, voltage_v: 230, plugged_in: true, | ||
| min_charge_w: 4140, max_charge_w: 7360, allowed_steps_w: [0, 4140, 6900, 11040], | ||
| }); | ||
| assert.equal(ui.slider.max, '10'); | ||
| assert.equal(ui.readout.textContent, '10 A · 6.9 kW'); | ||
| }); | ||
|
|
||
| test('without a table the top is max_charge_w, as before', () => { | ||
| const ui = build({ id: 'garage', phases: 3, voltage_v: 230, min_charge_w: 4140, max_charge_w: 11040 }); | ||
| assert.equal(ui.slider.min, '6'); | ||
| assert.equal(ui.slider.max, '16'); | ||
| assert.equal(ui.readout.textContent, '16 A · 11.0 kW'); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the highest table entry is below
max_charge_wand rounds down to whole amps, this change makes that previously reachable charging level impossible to request. For example, at three phases and 230 V, a maximum of 11,000 W with steps ending in[9700, 10400]previously submitted 11,040 W, which Core clamped to 10,400 W. The new maximum is 15 A, submitting only 10,350 W;clampManualPower→floorChargeWthen selects 9,700 W, and the slider cannot go higher. Preserve the exact top-step wattage in the submitted hold or otherwise ensure the amp conversion does not lower the ceiling below that step, and add a non-whole-amp regression case.Useful? React with 👍 / 👎.