Scaffolds the repo with agent workflow config (AGENTS.md, .gitignore), openspec tooling, and the perfectdraft-integration change proposal with design, specs (api-client, config-flow, entities, hacs-packaging), and implementation tasks — ready for apply phase. Made-with: Cursor
5.2 KiB
5.2 KiB
1. Repository scaffolding and HACS packaging
- 1.1 Create
custom_components/perfectdraft/directory with__init__.pyandconst.py(domain, API base URL, x-api-key, reCAPTCHA site key, default poll interval) - 1.2 Create
manifest.jsonwith all required HA + HACS fields (domain, name, version, config_flow, iot_class, codeowners, documentation, issue_tracker) - 1.3 Create
hacs.jsonat repository root with name, render_readme, homeassistant minimum version - 1.4 Create
strings.jsonandtranslations/en.jsonwith config flow step titles, field labels, error messages, and options flow labels
2. API client
- 2.1 Create
api.pywithPerfectDraftApiClientclass — constructor takesaiohttp.ClientSession, stores base URL and API key - 2.2 Implement
authenticate(email, password, recaptcha_token)— POST to/authentication/sign-in, return token triple, raiseAuthenticationErroron failure - 2.3 Implement
refresh_access_token(refresh_token)— attempt token refresh, raiseAuthenticationErrorif refresh token is invalid - 2.4 Implement
get_user_profile()— GET/api/mewith access token header, auto-retry on 401 via refresh - 2.5 Implement
get_machine_details(machine_id)— GET/api/perfectdraft_machines/{machine_id}with access token header, auto-retry on 401 via refresh - 2.6 Define exception classes:
PerfectDraftApiError,PerfectDraftConnectionError,AuthenticationErrorinexceptions.py
3. Config flow
- 3.1 Create
config_flow.pywithPerfectDraftConfigFlow—async_step_usershows email + password form - 3.2 Implement external step for reCAPTCHA —
async_step_recaptchainitiates external step,async_step_recaptcha_donereceives the token - 3.3 Create
static/recaptcha.html— loads reCAPTCHA v3 JS with the site key, generates token invisibly, posts back to HA callback URL - 3.4 Register an HA view to serve
recaptcha.htmland handle the callback (post token back into the config flow) - 3.5 Implement auth validation — after reCAPTCHA token received, call API
authenticate(), on success create config entry with tokens, on failure show error and return to user step - 3.6 Set unique ID from user email (or account ID from API response) and call
_abort_if_unique_id_configured - 3.7 Implement
async_step_reauth— re-authenticate flow for expired refresh tokens (email/password + reCAPTCHA again) - 3.8 Implement
OptionsFlowHandler— form with polling interval (integer seconds, default 900, min 60)
4. Data coordinator
- 4.1 Create
coordinator.pywithPerfectDraftDataUpdateCoordinatorextendingDataUpdateCoordinator - 4.2 Implement
_async_update_data— callget_user_profile()to get machine ID, thenget_machine_details(machine_id), return raw response dict - 4.3 Handle
AuthenticationErrorin update — trigger config entry reauth flow - 4.4 Handle
PerfectDraftApiError/PerfectDraftConnectionError— raiseUpdateFailed - 4.5 Support dynamic interval — read from config entry options, update interval when options change
5. Integration setup
- 5.1 Implement
async_setup_entryin__init__.py— create API client, create coordinator, store inhass.data, forward to sensor + image platforms - 5.2 Implement
async_unload_entry— clean uphass.data, unload platforms - 5.3 Implement
async_migrate_entrystub for future config entry version changes - 5.4 Listen for options updates — reload coordinator interval when options change
6. Sensor entities
- 6.1 Create
sensor.pywith basePerfectDraftSensorEntityextendingCoordinatorEntity+SensorEntity— shared DeviceInfo, unique ID pattern - 6.2 Implement
PerfectDraftTemperatureSensor— device_class TEMPERATURE, unit °C, state_class MEASUREMENT, reads temperature from coordinator data - 6.3 Implement
PerfectDraftPercentRemainingSensor— unit %, state_class MEASUREMENT, icon mdi:keg, reads volume/remaining from coordinator data - 6.4 Implement
PerfectDraftDaysToExpirySensor— unit d, icon mdi:calendar-clock, reads expiry from coordinator data - 6.5 Implement
PerfectDraftKegNameSensor— string state, icon mdi:beer, reads keg name/brand from coordinator data - 6.6 Handle "no keg loaded" state — sensors report None/unavailable when no keg is present
7. Image entity
- 7.1 Create
image.pywithPerfectDraftKegImageextendingCoordinatorEntity+ImageEntity - 7.2 Implement image URL sourcing from coordinator data — serve the keg artwork URL from the API response
- 7.3 Handle missing image — report unavailable when no image URL in data
8. Integration testing and polish
- 8.1 Manually test full flow: add integration → reCAPTCHA step → auth → entities appear with real data
- 8.2 Verify HACS installation: add repo as custom repository in HACS, confirm it downloads and installs correctly
- 8.3 Verify options flow: change polling interval, confirm coordinator respects new interval
- 8.4 Verify reauth flow: invalidate tokens, confirm HA prompts for re-authentication
- 8.5 Document actual API response field names discovered during testing in code comments and update specs if needed