# golles/ha-knmi architecture

> Architecture diagram of the GitHub repository golles/ha-knmi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/golles/ha-knmi
- Repository: https://github.com/golles/ha-knmi

## Overview

##### Project type and purpose
- This is a Home Assistant “custom component” (plugin) named KNMI.
- Purpose: fetch weather data from the KNMI API and expose it as Home Assistant entities (sensors, binary_sensors, a weather entity, diagnostics).

##### File structure
- Top‐level directories and files related to development (CI, devcontainer, scripts, tests) can be set aside when drawing the runtime architecture.
- The runtime code lives under custom_components/knmi/:
- manifest.json – metadata used by HA and HACS
- config_flow.py – sets up the integration via the UI and stores a ConfigEntry
- api.py – REST client for the external KNMI API
- coordinator.py – DataUpdateCoordinator that polls api.py on a schedule
- sensor.py, binary_sensor.py, weather.py, diagnostics.py – entity platforms that read from the Coordinator and push states into HA
- const.py – shared constants
- translations/ – language files (en, nl) for UI labels

##### Key insights from the README
- Configuration is done via the HA UI (config_flow).
- The integration registers multiple entity types (binary_sensors, sensors, a weather entity, diagnostics).
- Data flows: KNMI API → Coordinator → Entities → HA frontend.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Home Assistant Environment
    subgraph "Home Assistant"
        UI["Home Assistant UI"]:::frontend
        Core["HA Core State Machine"]:::core
    end

    %% KNMI Custom Integration
    subgraph "KNMI Integration" 
        IL["__init__.py"]:::integration
        MF["manifest.json"]:::integration
        CF["config_flow.py"]:::integration
        CONST["const.py"]:::integration
        COORD["coordinator.py"]:::integration
        API["api.py"]:::integration

        subgraph "Entity Platforms"
            SENSOR["sensor.py"]:::integration
            BINARY["binary_sensor.py"]:::integration
            WEATHER["weather.py"]:::integration
            DIAG["diagnostics.py"]:::integration
        end

        subgraph "Translations & Assets"
            EN["en.json"]:::integration
            NL["nl.json"]:::integration
            ICONS["icons.json"]:::integration
        end
    end

    %% External & Distribution
    HACS["HACS"]:::external
    KNMIAPI["External KNMI REST API"]:::external

    %% Data Flow & Interactions
    UI -->|"+ Integrate"| CF
    CF -->|"writes ConfigEntry"| Core
    Core -->|"loads Integration"| IL
    HACS -->|"installs"| MF

    Core -->|"creates Coordinator"| COORD
    COORD -->|"uses constants"| CONST
    COORD -->|"schedules update_data()"| COORD
    COORD -->|"calls"| API
    API -->|"HTTP GET /weather"| KNMIAPI
    KNMIAPI -->|"JSON payload"| API
    API -->|"return JSON"| COORD

    COORD -->|"update_data() callback"| SENSOR
    COORD -->|"update_data() callback"| BINARY
    COORD -->|"update_data() callback"| WEATHER
    COORD -->|"update_data() callback"| DIAG

    SENSOR -->|"entity.set_state()"| Core
    BINARY -->|"entity.set_state()"| Core
    WEATHER -->|"entity.set_state()"| Core
    DIAG -->|"entity.set_state()"| Core

    Core -->|"state changes"| UI

    %% Click Events
    click MF "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/manifest.json"
    click CF "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/config_flow.py"
    click API "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/api.py"
    click COORD "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/coordinator.py"
    click SENSOR "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/sensor.py"
    click BINARY "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/binary_sensor.py"
    click WEATHER "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/weather.py"
    click DIAG "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/diagnostics.py"
    click CONST "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/const.py"
    click IL "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/__init__.py"
    click EN "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/translations/en.json"
    click NL "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/translations/nl.json"
    click ICONS "https://github.com/golles/ha-knmi/blob/main/custom_components/knmi/icons.json"

    %% Styles
    classDef frontend fill:#D6E9FE,stroke:#0B67A1,color:#0B67A1;
    classDef core fill:#B3E6B3,stroke:#257A25,color:#257A25;
    classDef integration fill:#E8F8E0,stroke:#2E8B57,color:#2E8B57;
    classDef external fill:#FFE5CC,stroke:#E65C00,color:#E65C00;
```
