Repository navigation
fix(web): pair a phone in one tap, with the Cloud terms on the button - #2094
Conversation
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]>
5bf70e3 to
3889662
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| setHidden("app-link-terms", !(s.enabled && cloudNeedsTerms(cloud))); | ||
| setEnabled(s.enabled); |
There was a problem hiding this comment.
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 👍 / 👎.
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.mddid not mention thatstep.
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 policyftw-cloud-2026-10-v3. Accepted termsgate the readable copy and the statistics that come with Cloud
(
cloudRequiresStatistics,cloudUnderOlderTerms). Core never gated apairing code on the terms:
handleAppLinkPairingchecks the LAN door, therole 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
GET /api/cloudsays the terms are available and notaccepted, the pairing buttons first send the grant the Cloud panel sends
(scopes and policy from
GET /api/cloud/stats-policy), then ask for thecode. 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).
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.code and as Core puts in the QR's LAN hint.
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: falseand restartsthrough 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.
window.FTWHomeAssistant, whichhome-assistant.jssets on pages Core serves through ingress): the page'sorigin 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.
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.
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 sendsfirst.
Evidence
node --test web/app-link-tab.test.mjs web/app-link-sharing.test.mjs: 54pass. 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 thefirst round of new tests fail.
npm test: 1000 pass, on the branch rebased onto61691d53.GOFLAGS=-p=3 nice -n 10 make verify: "verify: vet + test + build clean", exit 0.sim-ferroampandsim-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/boxso it never dialled FTW Cloud. Headless Chrome on the Mac's LAN address,
at 1280×900 and 390×844:
phone. Statistics are included with Cloud." and no code.
"Box address: http://:8131", Open, Copy and the spoken
fallback.
GET /api/cloudthen readslink: on,state: on,cloudTermsAccepted: true,policy: ftw-cloud-2026-10-v3,grantedBy: lan, purposesserveandstats. The Core log hasaudit: FTW Cloud grant granted … by=lan. The Cloud panel appears belowthe pairing with Turn FTW Cloud off.
app_link.enabled: false: the switch and restart show, thebuttons stay off, and the terms line stays hidden.
window.FTWHomeAssistant = trueset before opening Settings: onetap 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.
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/statusreadenabled: falseand/api/configapp_link.enabled: false; the page showed the switch, unticked, and"Off. Turn it on above, then choose Save and restart FTW."
Not tested
payload and the claim route did not change.
stored the grant, but nothing reached
cloud.ftw.energy.browser; the ingress rewrite of the new
/api/cloudpaths was read inhome_assistant.go, not run.Decided in review
sentence that was false.
FTWStatistics.cloudAccepted()inweb/project-statistics.jsnow has nocaller. 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