Skip to content

fix(web): pair a phone in one tap, with the Cloud terms on the button - #2094

Merged
frahlg merged 4 commits into
masterfrom
onboarding-pairing-one-step
Nov 28, 2026
Merged

frahlg merged 4 commits into
masterfrom
onboarding-pairing-one-step

Conversation

@frahlg

@frahlg frahlg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Problem

Rows 5 and 7 of the onboarding review of 27 November. On a new box,
Settings → FTW app refused Show pairing code with "Accept the Cloud terms
above before pairing a phone". The terms sat in a separate panel, folded
under "Use FTW Cloud and the app". docs/pairing.md did not mention that
step.

The intro said the app talks to the box "when you are away" and that on the
same Wi-Fi "no pairing needed", so the app sounded free of pairing at home.
It is not: the app uses the home network only to trade a code, then reaches
the box through FTW Cloud. The intro also said Sourceful "cannot read"
readings. That stops being true once the Cloud terms are accepted: the grant
sends a readable copy (live, history, plan, health, events).

The box address showed beside a spoken code but not beside the QR. The app
link switch and its restart showed on every box, though a new box runs the
link.

What Core gates

Core records acceptance in the Cloud grant (POST /api/cloud/grant,
cloudlink.Link.Grant) under policy ftw-cloud-2026-10-v3. Accepted terms
gate the readable copy and the statistics that come with Cloud
(cloudRequiresStatistics, cloudUnderOlderTerms). Core never gated a
pairing code on the terms: handleAppLinkPairing checks the LAN door, the
role and the house-password rule only. The page held the only gate. This PR
leaves Core as it is and changes no Go code.

Change

  • One tap. When GET /api/cloud says the terms are available and not
    accepted, the pairing buttons first send the grant the Cloud panel sends
    (scopes and policy from GET /api/cloud/stats-policy), then ask for the
    code. If the box refuses the grant, for example before the house password
    is entered, the page shows the box's sentence in red and makes no code. A
    build with no Cloud service has nothing to accept and pairs as before.
    This matches the app, where pairing accepts the terms (srcfl/ftw-app#220).
  • One line beside the buttons, shown until the terms are accepted: "The
    app reaches this box through FTW Cloud, which keeps a readable copy of your
    energy data. Pairing accepts its terms. The box runs without it." "terms"
    links to ftw.sourceful.energy/privacy, as the app does.
  • Box address beside the QR: the page's own origin, as for the spoken
    code and as Core puts in the QR's LAN hint.
  • Switch and restart prominent only while the link is off, or saved on
    and not yet running. While the link runs, a quiet text button, Turn off
    the app link…
    , sits below the pairing, so the owner can always stop it
    at the box. It asks once, saves app_link.enabled: false and restarts
    through the same path as the switch: the uplink starts and stops only with
    Core. The sentence about the restart went; the status line and the confirm
    dialog already say it.
  • Inside the Home Assistant app (window.FTWHomeAssistant, which
    home-assistant.js sets on pages Core serves through ingress): the page's
    origin is Home Assistant's ingress URL and the box's own port is closed.
    The page hides the address line, Use a pairing code and the read-out
    fallback, and keeps the QR and the pairing link, which go through FTW
    Cloud. See feat(ftw-0x-beta): open FTW inside Home Assistant, find its MQTT broker, name it FTW (beta) home-assistant-addons#56.
  • Cloud panel below the pairing, shown only while Cloud is in use or
    being deleted. While Cloud is off, pairing is the way in. Below, the panel
    cannot push a fresh code out of view when it appears after the tap.
  • Intro: "This is not the Sourceful (Zap) app. The FTW app needs
    pairing, at home and away. A browser on your home Wi-Fi needs none."
  • docs/pairing.md: the steps as they now are, and the grant the page sends
    first.

Evidence

  • node --test web/app-link-tab.test.mjs web/app-link-sharing.test.mjs: 54
    pass. New tests cover: the grant goes before the code, with the policy's
    scopes; a refused grant makes no code; terms the page could not read make no code; no grant once accepted or on a
    build without Cloud; the terms line hides after acceptance and while the
    link is off; the Cloud panel hides while Cloud is off; the address shows
    beside the QR; the switch hides while the link is on and running; the off action shows
    only then, asks once, saves the setting off before the restart, puts the
    setting and the switch back when the save fails, and changes nothing when
    cancelled. Run against the old app.js, 6 of the
    first round of new tests fail.
  • npm test: 1000 pass, on the branch rebased onto 61691d53.
  • GOFLAGS=-p=3 nice -n 10 make verify: "verify: vet + test + build clean", exit 0.
  • Fresh-state Core from this source with the in-tree sim-ferroamp and
    sim-sungrow, port 8131, an empty data dir. Built with
    -X github.com/srcfl/ftw/go/internal/cloudlink.Endpoint=wss://127.0.0.1:9/v1/box
    so it never dialled FTW Cloud. Headless Chrome on the Mac's LAN address,
    at 1280×900 and 390×844:
    • Before: the tap shows "Accept the Cloud terms above before pairing a
      phone. Statistics are included with Cloud." and no code.
    • After: one tap shows the QR, "Works once, for about 10 more minutes.",
      "Box address: http://:8131", Open, Copy and the spoken
      fallback. GET /api/cloud then reads link: on, state: on,
      cloudTermsAccepted: true, policy: ftw-cloud-2026-10-v3,
      grantedBy: lan, purposes serve and stats. The Core log has
      audit: FTW Cloud grant granted … by=lan. The Cloud panel appears below
      the pairing with Turn FTW Cloud off.
    • With app_link.enabled: false: the switch and restart show, the
      buttons stay off, and the terms line stays hidden.
    • With window.FTWHomeAssistant = true set before opening Settings: one
      tap shows the QR, its expiry, Open in FTW on this phone and Copy
      pairing link
      ; no address, no Use a pairing code, no read-out
      button. Unit tests cover this case and the plain box.
    • Running link: Turn off the app link… shows below the pairing. With
      the confirm accepted, the save opened the shell's restart dialog and
      Core exited for its restart. Started again on the same data,
      /api/app-link/status read enabled: false and /api/config
      app_link.enabled: false; the page showed the switch, unticked, and
      "Off. Turn it on above, then choose Save and restart FTW."
    • Screenshots are local, not attached.

Not tested

  • A real phone scanning the QR or using the code after this change. The QR
    payload and the claim route did not change.
  • The grant against the real FTW Cloud. The test build linked the home and
    stored the grant, but nothing reached cloud.ftw.energy.
  • A box with the house password on. A unit test covers the refused grant.
  • Safari on an iPhone. Only headless Chrome.
  • A real Home Assistant ingress page. The flag was set by hand in the
    browser; the ingress rewrite of the new /api/cloud paths was read in
    home_assistant.go, not run.
  • A box whose Cloud runs under older terms, or is being deleted.

Decided in review

  • Keep the longer terms line on the box: it is true, and it replaces a
    sentence that was false.
  • FTWStatistics.cloudAccepted() in web/project-statistics.js now has no
    caller. It goes in a later PR.

No open PR touches these files. Other onboarding pieces (install, plan,
guide, overview, docs) are separate PRs.

🤖 Generated with Claude Code

frahlg and others added 4 commits November 28, 2026 06:53
Settings → FTW app refused Show pairing code until the FTW Cloud terms
were accepted in a separate panel. Core never gated pairing on the terms;
only the page did. Pairing now accepts the terms, as it does in the app:
a line beside the buttons says the app reaches the box through FTW Cloud,
which keeps a readable copy, and that pairing accepts its terms. The tap
posts the same POST /api/cloud/grant as the Cloud panel when GET /api/cloud
reports the terms not yet accepted, then asks for the code. A refusal from
the box stops the pairing and shows why.

The box address now shows beside the QR as well as beside a spoken code.
The app link switch and its restart show only while the link is off. The
Cloud panel moves below the pairing and shows only while Cloud is in use,
so it cannot push a fresh code out of view. The intro no longer says the
app works at home without pairing, or that Sourceful can read nothing.

docs/pairing.md describes the steps as they now are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
Hiding the switch while the link ran left the box page with no local way
to stop it. A small text button, Turn off the app link…, now sits below
the pairing while the link runs. It asks once, saves app_link.enabled off
and restarts through the same path as the switch, since the uplink only
starts or stops with Core. The switch and its restart stay prominent only
while the link is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
Inside the Home Assistant app the page's origin is Home Assistant's
ingress URL and the box's own port is closed. The box address beside the
QR would point nowhere, and a short code is traded at that address, so the
page now hides the address line, Use a pairing code, and the read-out
fallback when window.FTWHomeAssistant is set. The QR and the pairing link
go through FTW Cloud and stay. Tests cover both cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
… save

When /api/cloud said the terms were not accepted but the stats-policy read
failed, the pairing went on and showed a code with the terms unaccepted.
It now stops with an error, as a refused grant does.

Turn off the app link… set app_link.enabled off before the save, which
the save needs to carry it. If the save failed, the page went on saying
off while the box had it on, and a later Save elsewhere would have turned
it off unasked. A failed save now puts the setting and the switch back,
says "Could not save settings", and does not restart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the onboarding-pairing-one-step branch from 5bf70e3 to 3889662 Compare November 28, 2026 05:53
@frahlg
frahlg marked this pull request as ready for review November 28, 2026 05:55
@frahlg
frahlg merged commit 48d9b62 into master Nov 28, 2026
16 checks passed
@frahlg
frahlg deleted the onboarding-pairing-one-step branch November 28, 2026 05:55
@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-28T05:57:07.490724Z 3889662 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: 38896620d8

ℹ️ 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/settings/tabs/app.js
Comment on lines +303 to 304
setHidden("app-link-terms", !(s.enabled && cloudNeedsTerms(cloud)));
setEnabled(s.enabled);

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 Require known Cloud status before enabling pairing

If the initial /api/cloud request fails while /api/app-link/status succeeds, readJSON() returns null, so this hides the terms disclosure but still enables the pairing buttons. If the Cloud request succeeds when the user subsequently clicks, acceptCloudTerms() automatically posts /api/cloud/grant, enabling the readable Cloud copy without ever showing the notice that pairing accepts those terms. Keep pairing disabled until Cloud status is known, or otherwise ensure the disclosure is shown before a click can grant access; a failed status request should not be treated as an explicit available: false response.

Useful? React with 👍 / 👎.

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