Skip to content

feat(setup): add devices the way Settings does, and test each one - #2100

Merged
frahlg merged 12 commits into
masterfrom
onboarding-guide-one-flow
Nov 28, 2026
Merged

frahlg merged 12 commits into
masterfrom
onboarding-guide-one-flow

Conversation

@frahlg

@frahlg frahlg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Problem

The onboarding review of 27 November found that the setup guide adds devices its own way (rows 2, 3, 12, 14 and 16):

  • Steps 3 to 6 never tested a device. A wrong port gave a green LIVE with empty circles.
  • The driver list was filtered on a guess from the port. The guide asked for a port and Unit ID the driver already knows.
  • Four chargers sat in a list of their own. That list wrote an ev_charger block that nothing at runtime reads, so a charger added there never ran.
  • Nothing said what to turn on at the device, such as Modbus TCP.
  • An empty price area silently became SE3, and the guide picked SE3 for a Swedish owner who chose nothing.
  • The welcome page showed an AI-assistant card. Nothing led from the guide to the app.

Fredrik decided on 28 November that the planner is on from the start on a new box.

Paired PRs: srcfl/device-drivers#283 adds the hints this PR shows. #2098 makes Core start a new box in the planner's control mode; this guide only writes planner.enabled and battery_export, and sets no control mode. The plan runs from the first start only with both merged.

Change

  1. One device flow. The catalog search, catalog card, new-device driver block and connection test moved out of Settings → Devices into web/device-flow.js. Settings and the guide both use them. The guide's four device steps are now one step: scan, find the driver, give the address, add. Adding runs Test connection. A device that does not answer stays out of the settings until the owner fixes it or picks Add anyway (for a device that is off now). The port and Unit ID sit under Advanced, filled from the scan or the driver. Chargers are devices like the rest; the hard-coded list is gone.
  2. First start. The first-start server had no /api/drivers/test, and its scan gave open ports only. Both now run the same code as the running box (api.FirstRunProbes) with the same Modbus and MQTT clients. No password exists yet, so two limits apply: the test runs only a .lua file inside the bundled or user driver directory ({"lua":"/etc/hosts"} is refused before the file is read), and one test or scan runs at a time (a second caller gets 429). The probe still refuses loopback targets, and nothing is written.
  3. setup_hint. Core reads an optional one-line setup_hint from a driver's DRIVER block, or its signed header, into /api/drivers/catalog. A driver without one loads as before, and the key is left out of the JSON. The card shows the hint, and so does a failed test, in the guide and in Settings. feat(drivers): setup_hint says what to switch on in the device device-drivers#283 adds the hints. This PR does not move drivers/BUNDLED_SOURCE.json; the pin moves in its own PR after that one merges.
  4. Reads only. The card says "reads only" for a read-only driver with a battery or solar, such as Huawei, as well as for the chargers, cars and heat pumps driver-control.js already named. A meter, which is only ever read, says nothing. A driver whose DRIVER block does not state read_only says nothing: unstated stays unknown. A read-only driver with a battery now gets battery_telemetry_only whatever its protocol, as the guide already did, so Settings keeps a Huawei battery's reading too.
  5. Planner on. The guide writes planner: {enabled: true, battery_export: "not_allowed"}. Core seeds battery_export from YAML on first boot (config.ResolvePlannerPrefs), so Plan does not ask about selling. Checked on the test box: /api/status says battery_export: not_allowed.
  6. A site meter before Start FTW. Core refuses devices with no site meter, so a home with only a charger or a solar-only inverter used to get a raw 422 at Start FTW. The devices step now says "FTW needs a meter for the whole home: add your electricity meter, a P1 reader, or an inverter that measures the grid." The review repeats it and Start FTW stays off until one is added. A meter added unticked offers "Measures the whole home" in the list. Any refusal from Core shows its reason beside the button. Core is unchanged, and a charger is never marked the site meter.
  7. Price area asked once. Step 2 asks it and chooses nothing; a country with one area asks nothing. With no area the guide saves no price provider and the review says "No price area. FTW will not fetch prices or plan by price until you choose one in Settings → Price." An existing box with prices on and no area keeps SE3, and /api/status now carries price_area_note: "Price area not set, using SE3" so a client can show it.
  8. Start and end. No AI-assistant card. The guide ends with one line: get the FTW app for iPhone (the App Store link ftw.energy uses) and pair it from Settings → FTW app. home-assistant.js keeps only its flag, since the card it adjusted is gone. POST /api/setup/assistant stays for agents and scripts.
  9. Words. "Site name" is "Home name". The fixed-address tip is one plain line. No MPC, SoC or "set price.zone" in the guide.

The changeset is minor: a visible new capability, and new boxes start with the planner on. The owner approves the minor.

Evidence

All local, on this branch.

  • npm test: 1007 of 1007 pass, on master 48d9b62.
  • go test ./internal/drivers/ ./internal/api/ ./internal/prices/ ./internal/config/ ./cmd/ftw/: all pass.
  • make verify (with GOFLAGS=-p=3): verify: vet + test + build clean, 88 Go packages ok, on master 48d9b62.
  • New tests: catalog_setup_hint_test.go (with and without the key, signed header, every bundled driver), api_setup_hint_test.go (catalog JSON), bootstrap_driver_test_test.go (probe with no settings, loopback refused, nothing written, files outside the driver directories refused, one probe or scan at a time), api_price_area_test.go, and the guide run through its real handlers in web/setup-connection.test.mjs: test on add, failure with hint, Add anyway, scan, Zap, cloud charger, one site meter, charger-only and solar-only homes stopped before Core with a meter then letting them through, Core's 422 reason shown in place, price area, planner, a hostile secret key. web/driver-catalog-search.test.mjs now runs Settings' catalog fetch and draws the cards; it failed on a call I had missed in the move and passes with the fix.
  • A full first start in headless Chrome against a Core built from this branch (port 8133 by a build overlay), an empty data directory and sim-sungrow on port 15502. Local driver copies carried the hints from feat(drivers): setup_hint says what to switch on in the device device-drivers#283. The scan reply was stubbed with the simulator, so no real LAN scan ran.
    • Sungrow from the scan: the test passed and read grid, solar and battery.
    • Huawei on port 15503: "FTW could not read this device", the Huawei hint, the error, and Add anyway. It stayed out.
    • Review without a price area shows the notice; with SE3 it names "SE3 · Stockholm".
    • Saved, restarted, overview live: grid, solar, battery and fuse values from the simulator. /api/status: driver sungrow ok, battery_export: not_allowed, no price_area_note.
    • A charger-only home on a fresh box: the devices step and the review say a meter is needed, and Start FTW is off. After Sungrow is added on 15502 the line goes and Start FTW is on. The Easee account list and its test reply were stubbed in the browser, so no vendor cloud was contacted.
    • curl to the first-start server with {"lua":"/etc/hosts"}: {"error":"driver must be one of this box's drivers"}.
    • Settings → Devices on the same box: the Huawei card says "reads only" and shows its hint. Test connection passes on port 15502 and fails on 15503 with the Sungrow hint.
    • Screenshots of each step at 1280×900 and 390×844 were taken locally. A human still needs to look at the guide in a browser.
  • git merge-tree against feat(prices): static / time-of-use tariff so planning works outside Europe #1051's head: web/setup.html, go/internal/prices/prices.go, and the price lines in renderReview and buildConfig merge cleanly.

#1051 has right of way

#1051 (static tariff) touches web/setup.js, web/setup.html and go/internal/prices/prices.go. This PR leaves its hunks alone:

Not tested

  • Real hardware: a real scan on a LAN, a device with Modbus TCP off, a cloud charger sign-in against Easee or Zaptec. The cloud path ran only against a stubbed reply.
  • Home Assistant ingress, where the guide skips the house password.
  • A release build with Energyplan. On the dev build (Core planner) the planner started, but its startup replan ran 2 s after boot, before the battery reported and prices arrived. The first plan came at the next quarter-hour replan, 15 minutes after the start; until then the overview said "Planning could not finish". The box ran in self_consumption, since master does not yet seed the planner's control mode (fix(web): Use the plan turns the planner on, and a new box plans from its first start #2098 does). A replan on the first battery reading and prices may be worth a look in fix(web): Use the plan turns the planner on, and a new box plans from its first start #2098 or after it.
  • Tibber, a car, a NIBE local API and MyUplink in the guide. Cars and OAuth sign-ins send the owner to Settings → Devices; Tibber gets an address field it does not use, as it already did in Settings.
  • price_area_note is in /api/status, but no screen shows it yet. The overview or Settings → Price can show it in a later PR.

🤖 Generated with Claude Code

frahlg added a commit that referenced this pull request Nov 28, 2026
A vehicle driver after a restart with the car away never answers, so the
overview said "<car> has never answered" and LIVE stayed dark for the whole
house until the car came home. Core now marks a driver that only reads a
car vehicle_only on /api/status: its catalog entry declares the vehicle
capability and nothing else, or, without an entry, it has only vehicle
readings. The overview counts such a driver only when it reports an
error, did not start, or has a device fault. The app link rows do not
change.

When /api/status carries price_area_note (#2100, for a box with no price
area), the overview's price card shows it as one quiet line that opens
Settings -> Price. Without the field nothing shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
frahlg and others added 12 commits November 28, 2026 06:59
A driver may now say, in one sentence in its DRIVER block, what the owner
must turn on before FTW can read the device, such as Modbus TCP in an
inverter's settings. /api/drivers/catalog and signed metadata carry it as
setup_hint. A driver without one loads as before and the key is left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The setup guide runs on the first-start server, which had no
/api/drivers/test. It now serves the same short probe Settings runs, with
the same Modbus and MQTT clients and the same refusal of loopback targets.
Nothing is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
A box with prices on and no price.zone keeps the SE3 fallback, so a
working site keeps its prices. /api/status now says "Price area not set,
using SE3" in price_area_note, so a client can show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Settings → Devices kept the catalog search, the catalog card, the driver
block for a new device and the connection test inside its tab. The setup
guide had its own weaker copy. They now live in web/device-flow.js, and
Settings runs them from there.

What Settings shows changes in three small ways:
- The card says "reads only" for any read-only driver with a battery or
  solar, such as a Huawei hybrid, as well as the chargers, cars and heat
  pumps it named before. A driver that does not state read_only says
  nothing.
- A card shows the driver's setup_hint, and a failed test shows it too.
- A read-only driver with a battery gets battery_telemetry_only on
  whatever protocol it uses, as the guide already did, so its battery
  reading is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The guide's steps 3 to 6 had their own device flow: no test, a driver
list filtered on a guess from the port, a port and Unit ID the driver
already knows, and four chargers in a list of their own that wrote an
ev_charger block nothing at runtime reads. A wrong port gave a green LIVE
with nothing in it.

One devices step now runs the shared flow: scan, find the driver in the
catalog, give the address, and add. Adding runs the connection test. A
device that does not answer stays out, with the driver's setup_hint and
the error, until the owner fixes it or chooses Add anyway. Chargers are
devices like the rest. The port and Unit ID sit under Advanced.

Also:
- A new box starts with the planner on and battery_export not_allowed,
  so Plan does not ask about selling on the first day.
- The price area is asked once, and never chosen for the owner. A
  country with one area asks nothing. With no area the guide saves no
  price provider and says so on the review, instead of Core pricing the
  home by SE3.
- The welcome page has no AI-assistant card. The guide ends with one
  line to the FTW app for iPhone and pairing from Settings → FTW app.
- The fixed-address note is one calm line. No MPC, SoC or
  "set price.zone" in the guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The fixed-address tip is a line of text, not a box that looks like a
field. A failed test carries the driver's setup hint, so the copy above
the form hides. The search box has the same style as the other fields,
links read in the page colour, and "Site name" is "Home name".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
The first-start server answered /api/scan?fingerprint=1 with open ports
only, so on a new box the guide could not say "that is a Sungrow". It now
runs the same driver fingerprints as the running box, with the same
Modbus client the device test uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
One call to the old search was left in the Devices tab, so Settings
stopped at "Loading catalog…". A test now runs the tab's catalog fetch
and draws the cards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Ambibox and other MQTT drivers name a default host; the guide now fills
it in, as it already did for Zap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Before a box has a password, anyone on the LAN can reach the first-start
device test and scan. The test now runs only a .lua file inside the
bundled or user driver directory, so {"lua":"/etc/hosts"} is refused
before the file is read. One test or scan runs at a time; a second caller
gets 429 until the first ends, so the box cannot be made to fan out port
scans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Core refuses devices with no site meter, so a home with only a charger or
a solar-only inverter got a raw 422 at Start FTW. The devices step now
says "FTW needs a meter for the whole home: add your electricity meter, a
P1 reader, or an inverter that measures the grid." The review repeats it
and Start FTW stays off until one is added. A meter added unticked offers
"Measures the whole home" in the list. Any refusal from Core shows its
reason beside the button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@frahlg
frahlg force-pushed the onboarding-guide-one-flow branch from a6faed5 to ffe2440 Compare November 28, 2026 06:03
frahlg added a commit that referenced this pull request Nov 28, 2026
* fix(web): the overview names a device that does not answer

With one driver on a wrong port the overview showed a green LIVE beside
empty circles and said nothing. LIVE now follows the two freshness facts
the apps use: the box answers this page, and every configured device
answers. Core grades each driver with the apps' own source-state ladder
and sends it on /api/status as src_state, with last_ok_age_ms; the app
link builds its source rows with the same function. The overview names
each device that does not answer, says what Core knows, and links to
Settings -> Devices.

The savings card names its baseline, "no solar or battery": that number
counts what the panels bring. Core sends the self-use baseline only from
the energy ledger, which a box in source-history mode never reads, so a
chosen self-use comparison now falls back to the named baseline instead
of a false zero. "Unknown" energy is neutral, not red, and Get help says
to ask in the FTW Discord with the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>

* fix(web): a car away does not dim LIVE; show the price area note

A vehicle driver after a restart with the car away never answers, so the
overview said "<car> has never answered" and LIVE stayed dark for the whole
house until the car came home. Core now marks a driver that only reads a
car vehicle_only on /api/status: its catalog entry declares the vehicle
capability and nothing else, or, without an entry, it has only vehicle
readings. The overview counts such a driver only when it reports an
error, did not start, or has a device fault. The app link rows do not
change.

When /api/status carries price_area_note (#2100, for a box with no price
area), the overview's price card shows it as one quiet line that opens
Settings -> Price. Without the field nothing shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>

---------

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg marked this pull request as ready for review November 28, 2026 06:19
@frahlg
frahlg merged commit 655fcca into master Nov 28, 2026
21 checks passed
@frahlg
frahlg deleted the onboarding-guide-one-flow branch November 28, 2026 06:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T06:21:14.656685Z ffe2440 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ffe2440bd3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/setup.js
Comment on lines +492 to +495
flow().test(read.driver).then(function (res) {
add.disabled = false;
if (res && res.ok) {
keepDevice(read.driver, 'ok', flow().readingWords(res));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore probe replies after the device selection changes

If the owner clicks Choose another while a connection test is pending, closeDeviceForm() clears pick, but this callback still calls keepDevice(), which dereferences pick.entry. I reproduced an unhandled TypeError by cancelling a pending successful test using the setup test harness. If another driver is selected before the reply arrives, the old driver is instead added with the new selection's catalog entry, giving it the wrong displayed identity and capabilities. Capture the selection for each test and discard its reply when that selection has been closed or replaced.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Nov 28, 2026
)

* feat(setup): bring back setup with ChatGPT or Claude on a new box

#2100 took the welcome step's assistant card away, so nothing called
POST /api/setup/assistant any more, while FTW Cloud's texts still send
people to "Start assistant setup" on the box's page.

A new box's welcome step now has one quiet link under Get started, "Set
up with ChatGPT or Claude instead". It opens the house password, typed
twice, and the "Start assistant setup" button. The button posts to
/api/setup/assistant as the old card did, waits for the box to restart
and then follows the reply's next, resolved from the page's folder so it
stays under Home Assistant's ingress prefix. A next that leaves the box
falls back to the Access page.

Under Home Assistant the form asks for no password: Core ignores one
there, because Home Assistant signs its users in. The old card asked
anyway. A running box shows no link, since only the first-start server
answers the call.

The guide's last step adds one line: you can connect ChatGPT or Claude
later from Settings → Access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>

* fix(setup): plain words and a way on when assistant setup stalls

Review of the assistant path on the welcome step:

- A lost reply said the browser's own error, such as "Failed to fetch".
  It now says "The box is restarting. Checking whether it has started…".
- After 30 tries the page said "before you try again" with the button
  still off. The button comes back with "Open the box, or try again."
  A retry is safe: Core refuses a second first-start write.
- A box that already has settings answers 409 from the first-start
  server, or 404 once it runs. Both now say "This box already has
  settings. Open the box instead." with the link, not Core's path text.
- Each wait for the restart gives up on one request after 3 seconds.
- The fields sit in a form, so Enter starts setup. Under Home Assistant
  the Start button takes focus when the form opens.

Tests cover the lost reply, the 30-try stop and its link, both refusals,
another refusal's own reason, Enter, and Home Assistant focus. A Go test
runs the real setup.js and setup.html through the ingress rewrite, so
the calls keep Home Assistant's prefix and the page built from Core's
reply does not get it twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>

---------

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.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