7 Commits
Author SHA1 Message Date
rickandCursor 133f7082cf fix(sensor): reject implausible temperature readings
An uninitialised probe reports -128 (0x80 read as a signed 8-bit
integer) while the refrigeration starts up. The cloud API relays it
verbatim and the sensor reported it as a real measurement, polluting
history graphs and long-term statistics.

Readings outside -20..50 C are now treated as firmware sentinels and
the sensor reports no value, so the state is 'unknown' and the recorder
excludes it. A range check is used rather than matching -128 exactly so
sibling sentinels are caught too. Both temperature fields are validated;
previously the details.temperature fallback was used unconditionally.

The sensor deliberately reports 'unknown' rather than going unavailable:
the coordinator poll succeeded and only the reading is missing, which
matches how every other sensor here signals absent data.

Logic lives in a new HA-free temperature.py so it can be unit-tested
without the Home Assistant harness, following the keg_detection.py
precedent.

Refs: Falkvinge/hassio-integration-perfectdraft-pro#4
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-06 16:11:07 +02:00
Brett Jenkins 9b3852b9fd Add active-keg detection and a keg name sensor
Resolves the tapped keg's product id to a beer name via a bundled
catalog (keg_catalog.json), exposing it as a new Keg sensor alongside
the existing Keg Remaining/Freshness sensors.
2026-07-05 00:49:29 +01:00
rickandCursor f5c9019802 feat: detect keg change by volume jump + manual reset button
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>
2026-05-31 21:04:44 +02:00
rick 5e4ef94cff Fix RestoreEntity: use state attributes instead of ExtraStoredData API
Made-with: Cursor
2026-04-13 12:17:15 +02:00
rick 70882b939e v0.2.0: Fix token refresh, HACS compliance, brand icon, keg freshness
Critical fix:
- Cognito refresh now parses response with content_type=None
  (was crashing after 1hr when access token expired)

HACS compliance:
- Added README.md with full setup instructions including the
  token generation command
- Fixed manifest.json URLs to point at actual repo
- Version bumped to 0.2.0

Brand:
- Added brand/icon.png (PerfectDraft glass icon from official app)

New sensor:
- Keg Freshness: 30-day countdown from keg insertion, detected
  via numberOfPoursSinceStartup reset + kegVolume near full,
  persisted across restarts via RestoreEntity

Polish:
- Fixed MALFORMED_ARGUMENT in token step description
- Cleaner description referencing README for instructions

Made-with: Cursor
2026-04-13 12:12:43 +02:00
rick 34a23a2814 Working integration with real API data
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
2026-04-12 17:18:03 +02:00
rick c24e3678a7 Implement PerfectDraft Pro HA integration (tasks 1–7)
Complete custom_components/perfectdraft/ with:
- Async API client (auth, refresh, machine polling)
- Config flow with reCAPTCHA v3 external step
- DataUpdateCoordinator for shared polling
- Sensor entities (temperature, % remaining, days to expiry, keg name)
- Image entity for keg artwork
- HACS-compliant packaging (manifest.json, hacs.json, translations)
- Configurable polling interval via OptionsFlow
- Reauth flow for expired refresh tokens

Group 8 (manual testing) deferred — requires live HA instance.

Made-with: Cursor
2026-04-11 19:09:44 +02:00