How johnan/homeassistant-pollenprognos works
Project type and purpose
• This is a Home Assistant custom integration (“Home Assistant Pollenprognos”) that pulls pollen forecasts for locations in Sweden from the external Pollenrapporten.se API, exposes them as Home Assistant sensor entities, and makes them available to the Home Assistant frontend (including Lovelace cards).
File structure
• Top-level support files & CI/CD:
• .github/workflows/*.yaml – CI for lint, validate, releases
• scripts/ – helper scripts (lint, setup, develop)
• manage/update_manifest.py – updates integration manifest version
• requirements.txt – development dependencies
• custom_components/pollenprognos/ – main integration code:
• manifest.json – integration metadata (domain, requirements)
• config_flow.py – UI-guided setup/credential flow in HA frontend
• api.py – lightweight wrapper over Pollenrapporten.se HTTP endpoints
• const.py – fixed constants (attribute keys, default values)
• entity.py – base class for Home Assistant entities (common logic)
• sensor.py – defines individual SensorEntity subclasses (pollen types, levels)
• translations/ & strings.json – localization support
README for additional insights
• Describes installation via HACS and Home Assistant UI
Main components and interactions
a. Components
• Home Assistant Core (event loop, entity registry, state machine)
• Pollenprognos Integration (the custom component)
– Config Flow submodule (UI setup)
– API Client submodule (api.py)
– Entity Model submodule (entity.py + sensor.py)
– Localization files (strings.json + translations folder)
• External Pollenrapporten.se REST API (HTTP service)
• Home Assistant Frontend (Lovelace dashboard displaying sensor cards)
• HACS (optional external installation source)
b. Relationships & data flows
1. User installs integration via HACS → integration files are placed under custom_components/
2. Home Assistant Core triggers config_flow → user enters location/credentials
3. Config_flow calls API client to validate config/user input
4. Scheduled polling: Integration’s API client issues HTTP GET to Pollenrapporten.se → returns JSON pollen data
5. Integration parses JSON → instantiates/updates SensorEntity objects → pushes new state into Home Assistant Core
6. Home Assistant Frontend queries Core for sensor states → renders Lovelace cards
c. Architectural patterns & principles
• Single-responsibility modules (API wrapper vs. entity definitions vs. config flow)
• Event-driven update loop via Home Assistant’s coordinator pattern (implicit in sensor.py)
• Localizable strings separated in JSON + translations (i18n)
• Manifest-driven dependency injection (manifest.json)
d. Key technologies & frameworks
• Python 3.x, Home Assistant Core integration API
• aiohttp or requests (indirect via Home Assistant HTTP helper)
• JSON translation files for i18n
• HACS for custom distribution