# beckalexander/esphome-component-dfrobot-c4001 architecture

> Architecture diagram of the GitHub repository beckalexander/esphome-component-dfrobot-c4001, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/beckalexander/esphome-component-dfrobot-c4001
- Repository: https://github.com/beckalexander/esphome-component-dfrobot-c4001

## Overview

This ESPHome component integrates the DFRobot C4001 mmWave presence sensor over UART. Users configure a sensor mode and expose entities; the hub exchanges commands and sensor reports with the module, then publishes occupancy, target measurements, versions, and configuration state. Configuration entities update hub settings, and the config-save action sends settings to the sensor for persistent storage. The README documents both Presence and Speed and Distance modes. Some entity implementations were not sampled, so their internal wiring is shown only where documented.

Main entry points: [`components/dfrobot_c4001/dfrobot_c4001.cpp`](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/dfrobot_c4001.cpp) (C4001 hub), [`components/dfrobot_c4001/__init__.py`](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/__init__.py) (Component setup), [`components/dfrobot_c4001/commands.cpp`](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/commands.cpp) (Commands and queue), [`components/dfrobot_c4001/number/number.cpp`](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/number/number.cpp) (Numeric settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["ESPHome Integration"]
  node_config["Component setup<br/>[__init__.py]"]
  node_hub["C4001 hub<br/>[dfrobot_c4001.cpp]"]
end

subgraph group_protocol["Sensor Protocol"]
  node_commands["Commands and queue<br/>[commands.cpp]"]
end

subgraph group_entities["Entities"]
  node_binary["Occupancy and config state<br/>[binary_sensor.py]"]
  node_sensors["Target measurements<br/>[sensor.py]"]
  node_text["Version reporting<br/>[text_sensor.py]"]
  node_numbers["Numeric settings<br/>[number.cpp]"]
  node_switches["Setting switches<br/>[switch.cpp]"]
  node_buttons["Control buttons<br/>[button.cpp]"]
end

node_user(("ESPHome user"))
node_uart["UART sensor"]

node_user -->|"configures"| node_config
node_config -->|"registers hub"| node_hub
node_hub -->|"queues commands"| node_commands
node_hub -->|"sends and reads"| node_uart
node_uart -->|"sensor reports"| node_hub
node_commands -->|"updates state"| node_hub
node_hub -->|"publishes occupancy"| node_binary
node_hub -->|"publishes targets"| node_sensors
node_hub -->|"publishes versions"| node_text
node_numbers -->|"sets parameters"| node_hub
node_switches -->|"sets switches"| node_hub
node_buttons -->|"invokes actions"| node_hub
node_user -->|"adjusts settings"| node_numbers
node_user -->|"toggles settings"| node_switches
node_user -->|"presses controls"| node_buttons

click node_config "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/__init__.py"
click node_hub "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/dfrobot_c4001.cpp"
click node_commands "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/commands.cpp"
click node_binary "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/binary_sensor.py"
click node_sensors "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/sensor.py"
click node_text "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/text_sensor.py"
click node_numbers "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/number/number.cpp"
click node_switches "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/switch/switch.cpp"
click node_buttons "https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/button/button.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_hub,node_user toneBlue
class node_commands toneAmber
class node_binary,node_sensors,node_text,node_numbers,node_switches,node_buttons toneMint
class node_uart toneIndigo
```

## Components

### ESPHome Integration

- [Component setup](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/__init__.py): `components/dfrobot_c4001/__init__.py`
- [C4001 hub](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/dfrobot_c4001.cpp): `components/dfrobot_c4001/dfrobot_c4001.cpp`

### Sensor Protocol

- [Commands and queue](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/commands.cpp): `components/dfrobot_c4001/commands.cpp`

### Entities

- [Occupancy and config state](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/binary_sensor.py): `components/dfrobot_c4001/binary_sensor.py`
- [Target measurements](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/sensor.py): `components/dfrobot_c4001/sensor.py`
- [Version reporting](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/text_sensor.py): `components/dfrobot_c4001/text_sensor.py`
- [Numeric settings](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/number/number.cpp): `components/dfrobot_c4001/number/number.cpp`
- [Setting switches](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/switch/switch.cpp): `components/dfrobot_c4001/switch/switch.cpp`
- [Control buttons](https://github.com/beckalexander/esphome-component-dfrobot-c4001/blob/main/components/dfrobot_c4001/button/button.cpp): `components/dfrobot_c4001/button/button.cpp`

### Other components

- **ESPHome user**
- **UART sensor**

## Connections

- ESPHome user → Component setup: configures
- Component setup → C4001 hub: registers hub
- C4001 hub → Commands and queue: queues commands
- C4001 hub → UART sensor: sends and reads
- UART sensor → C4001 hub: sensor reports
- Commands and queue → C4001 hub: updates state
- C4001 hub → Occupancy and config state: publishes occupancy
- C4001 hub → Target measurements: publishes targets
- C4001 hub → Version reporting: publishes versions
- Numeric settings → C4001 hub: sets parameters
- Setting switches → C4001 hub: sets switches
- Control buttons → C4001 hub: invokes actions
- ESPHome user → Numeric settings: adjusts settings
- ESPHome user → Setting switches: toggles settings
- ESPHome user → Control buttons: presses controls
