PerfectDraft's Cognito PreAuthentication Lambda now requires a "domain"
field in ClientMetadata. The api.perfectdraft.com /authentication/sign-in
gateway does not forward it, so every setup and reauth failed with
"PreAuthentication failed with error 'domain'" (#11, #12, #13).
authenticate() now calls Cognito InitiateAuth (USER_PASSWORD_AUTH)
itself, the endpoint token refresh already uses.
A failed sign-in now says what was rejected and why. A wrong email or
password returns to the credentials form; a rejected token stays on the
token step; both show Cognito's reason instead of the old blanket "token
may have expired", which hid this outage.
The README snippet copies the token to the clipboard. It captures copy()
up front because Chromium removes it once the console command returns.
Root cause and fix by @cesa030 in #11; confirmed in @brettjenkins' fork.
Co-authored-by: Cursor <cursoragent@cursor.com>
Keg-change detection previously fired only when the pour counter reset
to 0 while the keg read near full. That misses the common case where the
user swaps the keg and pours immediately, so pours never reads 0.
Detection now also fires on two volume-based signals (independent of the
pour counter): (b) remaining volume jumping from below 80% to at least
95%, and (c) any upward jump of at least 50 percentage points. The
decision logic is extracted to a dependency-free keg_detection module
with unit tests covering each trigger and the swap-then-pour case.
Adds a "Mark Keg Changed" button as a deterministic manual override,
wired to the freshness sensor via a dispatcher signal; the sensor now
tracks and restores last_volume alongside last_pours.
Bumps version to 0.3.0.
Co-authored-by: Cursor <cursoragent@cursor.com>
Breakthrough: discovered the web reCAPTCHA Enterprise key
(6LcZQiUo...) from perfectdraft.com with action "Magento/login"
is accepted by the /authentication/sign-in API endpoint when
generated from a real browser. Token refresh works via direct
AWS Cognito InitiateAuth (bypasses API gateway, no reCAPTCHA).
Cognito details extracted from JWT:
Pool: eu-west-1_UXWVyvlHR
Client: 57ddq2ppqg2jcpup06r2g1deur
Real API response fields mapped:
/api/me → perfectdraftMachines[].id
/api/perfectdraft_machines/{id} → details.temperature,
details.kegVolume, details.connectedState, details.doorClosed,
details.numberOfPoursSinceStartup, details.volumeOfLastPour,
details.firmwareVersion, details.serialNumber, setting.mode
Changes:
- api.py: Cognito direct refresh, correct sign-in endpoint
- config_flow.py: external step with web reCAPTCHA on HA page
- const.py: Cognito config, web reCAPTCHA key
- coordinator.py: real field name extraction
- sensor.py: 8 sensors with real field mappings (temperature,
keg remaining %, connection, door, pours, last pour, firmware, mode)
- Removed image.py (API doesn't expose keg images)
- Restored static/recaptcha.html with Enterprise JS
Made-with: Cursor
The Android reCAPTCHA Enterprise key cannot be used from any
non-Android context (browser, server, headless). Certificate
pinning prevents MITM token capture. Every approach to bypass
reCAPTCHA has been exhausted.
New approach: user provides UserId + RefreshToken (one-time
extraction from the PerfectDraft app via HTTP Toolkit or similar).
The integration validates by calling /auth/renewaccesstokens,
which does NOT require reCAPTCHA, then refreshes forever.
Changes:
- config_flow.py: two-step flow (email, then tokens), validates
via refresh endpoint, reauth asks for fresh tokens
- api.py: refresh_access_token() calls /auth/renewaccesstokens
with {UserId, RefreshToken}, removed authenticate() method,
added x-api-key header to all authenticated requests
- const.py: added CONF_USER_ID, removed reCAPTCHA constants
- __init__.py: passes user_id to client.set_tokens()
- strings.json + translations: updated for new flow steps
- Deleted recaptcha.py and static/recaptcha.html
- test_harness.py: updated for refresh-based flow
Made-with: Cursor
The Android key (6LdrqmAp...) only works with the Android SDK —
it rejects all web-based token generation with "Invalid domain."
Discovered that perfectdraft.com's web login uses a separate
Enterprise web key (6LcZQiUo...) with action "Magento/login".
Testing confirmed the API at api.perfectdraft.com accepts tokens
from this web key. The only remaining requirement is a high
reCAPTCHA score, which a real user's browser will provide.
The external step flow now uses:
- Enterprise JS (recaptcha/enterprise.js)
- Web site key: 6LcZQiUoAAAAAAO3JUjLiT470c-pNXbWyepuvMtV
- Action: Magento/login
Removed server-side token generation attempt from config flow
since it cannot produce high-score tokens.
Made-with: Cursor