This file provides guidance to AI coding assistants when working with code in this repository.
Home Assistant custom integration for displaying Too Good To Go (TGTG) surplus food item availability as sensors. Uses the tgtg-python library for API access.
# Install dependencies (requires Python 3.8+)
scripts/setup
# OR: python3 -m pip install --requirement requirements.txt
# Run Home Assistant locally on port 8123 for testing
scripts/develop
# OR: hass -c . --debug
# Format code (required before PR)
black .This is a config flow integration using modern Home Assistant patterns (2025+).
custom_components/toogoodtogo/__init__.py- Entry point: sets up coordinator and forwards to platformscustom_components/toogoodtogo/config_flow.py- UI-based configuration with email magic link authenticationcustom_components/toogoodtogo/coordinator.py- Data update coordinator with pagination, rate limiting, and smart pollingcustom_components/toogoodtogo/entity.py- Base entity class extending CoordinatorEntitycustom_components/toogoodtogo/sensor.py- Sensor platform using SensorEntityDescription patterncustom_components/toogoodtogo/diagnostics.py- Diagnostics support with sensitive field redactioncustom_components/toogoodtogo/manifest.json- Component metadata and tgtg library dependencycustom_components/toogoodtogo/strings.json- Translation strings (English)custom_components/toogoodtogo/translations/- Localized translations (en, de)
- Modern config flow integration with
async_setup_entry()andasync_unload_entry() TGTGUpdateCoordinatorextendsDataUpdateCoordinatorfor centralized data fetchingTGTGEntitybase class extendsCoordinatorEntityfor automatic state updates- One
TGTGSensorentity per TGTG item (from favorites or manually configured) - Device grouping - all sensors grouped under a single device per TGTG account
- Uses
runtime_datafor coordinator storage (modern HA pattern)
- Default: 15-minute polling interval
- Smart polling: 3-minute interval during sales windows (when items are likely available)
- API rate limiting: 500ms delay between API calls
- Adaptive: 1-hour delay on captcha/rate limit errors
- Pagination: Fetches ALL favorites pages (not just first 20)
Primary state is items_available (quantity). Extra attributes include:
- item_id, item_url
- item_price, original_value
- pickup_start, pickup_end
- soldout_timestamp
- orders_placed, total_quantity_ordered
- pickup_window_changed, cancel_until
- logo_url, cover_url
- latitude, longitude (pickup location)
GitHub Actions run on push/PR:
- Hassfest validation - Home Assistant manifest validation
- HACS validation - Community Store compatibility
- CodeQL - Security analysis
- Favorites list only updated when integration reloads (requires reload when adding/removing favorites in TGTG app)
- Token refresh handled via reauth flow when tokens expire