# alexxit/sonofflan architecture

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

- Interactive diagram: https://gitdiagram.com/alexxit/sonofflan
- Repository: https://github.com/alexxit/sonofflan

## Overview

SonoffLAN is a Home Assistant integration for controlling eWeLink/Sonoff devices through LAN, cloud, or both. The principal workflow configures an account and connection mode, obtains the device catalogue, maps device models and parameters to Home Assistant entities, then exchanges commands and state updates with devices. The README also documents multi-account/home support, diagnostics, custom entity classes, RF Bridge, and camera control. Some platform setup and service wiring are not shown in the sampled source; those links are limited to README claims or explicit calls.

Main entry points: [`custom_components/sonoff/core/ewelink/__init__.py`](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/__init__.py) (eWeLink registry), [`custom_components/sonoff/core/devices.py`](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/devices.py) (Device specifications), [`custom_components/sonoff/__init__.py`](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/__init__.py) (Integration lifecycle), [`custom_components/sonoff/core/ewelink/cloud.py`](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/cloud.py) (Cloud transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Setup and mapping"]
  node_config["Config flow<br/>[config_flow.py]"]
  node_integration["Integration lifecycle<br/>[__init__.py]"]
  node_device_specs["Device specifications<br/>[devices.py]"]
  node_entity_base["Entity base<br/>[entity.py]"]
end

subgraph group_runtime["Device runtime"]
  node_registry["eWeLink registry<br/>[__init__.py]"]
  node_cloud["Cloud transport<br/>[cloud.py]"]
  node_local["LAN transport<br/>[local.py]"]
end

subgraph group_platforms["Home Assistant entities"]
  node_switch["Switch and button<br/>[switch.py]"]
  node_light["Light entities<br/>[light.py]"]
  node_sensors["Sensor entities<br/>[sensor.py]"]
  node_climate["Climate entities<br/>[climate.py]"]
  node_cover["Cover entities<br/>[cover.py]"]
  node_other_platforms["Other entity platforms"]
end

subgraph group_integrations["Special capabilities"]
  node_camera["Camera protocol<br/>[camera.py]"]
  node_diagnostics["Diagnostics<br/>[diagnostics.py]"]
  node_health["System health<br/>[system_health.py]"]
  node_rf["RF Bridge support<br/>[remote.py]"]
end

node_user(("Home Assistant user"))
node_ha(("Home Assistant"))
node_ewelink_service["eWeLink service"]
node_lan_devices(("Sonoff devices"))

node_user -->|"configures"| node_config
node_config -->|"creates entry"| node_integration
node_ha -->|"starts integration"| node_integration
node_integration -->|"starts registry"| node_registry
node_registry -->|"uses cloud"| node_cloud
node_registry -->|"uses LAN"| node_local
node_cloud -->|"authenticates and fetches"| node_ewelink_service
node_cloud -->|"sends commands"| node_ewelink_service
node_local -->|"discovers and commands"| node_lan_devices
node_lan_devices -->|"reports state"| node_local
node_ewelink_service -->|"reports state"| node_cloud
node_cloud -->|"dispatches updates"| node_registry
node_local -->|"dispatches updates"| node_registry
node_registry -->|"selects classes"| node_device_specs
node_registry -->|"creates entities"| node_entity_base
node_device_specs -->|"maps devices"| node_switch
node_device_specs -->|"maps devices"| node_light
node_device_specs -->|"maps devices"| node_sensors
node_device_specs -->|"maps devices"| node_climate
node_device_specs -->|"maps devices"| node_cover
node_device_specs -->|"maps devices"| node_other_platforms
node_ha -->|"exposes controls"| node_switch
node_ha -->|"exposes controls"| node_light
node_ha -->|"exposes readings"| node_sensors
node_ha -->|"exposes controls"| node_climate
node_ha -->|"exposes controls"| node_cover
node_ha -->|"exposes entities"| node_other_platforms
node_switch -->|"sends commands"| node_registry
node_light -->|"sends commands"| node_registry
node_climate -->|"sends commands"| node_registry
node_cover -->|"sends commands"| node_registry
node_registry -->|"dispatches state"| node_switch
node_registry -->|"dispatches state"| node_light
node_registry -->|"dispatches state"| node_sensors
node_registry -->|"dispatches state"| node_climate
node_registry -->|"dispatches state"| node_cover
node_integration -->|"initializes on demand"| node_camera
node_integration -->|"registers command service"| node_rf
node_user -->|"requests report"| node_diagnostics
node_ha -->|"provides device data"| node_diagnostics
node_ha -->|"requests status"| node_health

click node_config "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/config_flow.py"
click node_integration "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/__init__.py"
click node_registry "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/__init__.py"
click node_device_specs "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/devices.py"
click node_entity_base "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/entity.py"
click node_cloud "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/cloud.py"
click node_local "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/local.py"
click node_switch "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/switch.py"
click node_light "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/light.py"
click node_sensors "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/sensor.py"
click node_climate "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/climate.py"
click node_cover "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/cover.py"
click node_other_platforms "https://github.com/alexxit/sonofflan/tree/master/custom_components/sonoff"
click node_camera "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/camera.py"
click node_diagnostics "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/diagnostics.py"
click node_health "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/system_health.py"
click node_rf "https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/remote.py"

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_integration,node_device_specs,node_entity_base,node_user toneBlue
class node_registry,node_cloud,node_local toneAmber
class node_switch,node_light,node_sensors,node_climate,node_cover,node_other_platforms toneMint
class node_camera,node_diagnostics,node_health,node_rf toneRose
class node_ha,node_ewelink_service,node_lan_devices toneIndigo
```

## Components

### Setup and mapping

- [Config flow](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/config_flow.py): `custom_components/sonoff/config_flow.py`
- [Integration lifecycle](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/__init__.py): `custom_components/sonoff/__init__.py`
- [Device specifications](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/devices.py): `custom_components/sonoff/core/devices.py`
- [Entity base](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/entity.py): `custom_components/sonoff/core/entity.py`

### Device runtime

- [eWeLink registry](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/__init__.py): `custom_components/sonoff/core/ewelink/__init__.py`
- [Cloud transport](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/cloud.py): `custom_components/sonoff/core/ewelink/cloud.py`
- [LAN transport](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/local.py): `custom_components/sonoff/core/ewelink/local.py`

### Home Assistant entities

- [Switch and button](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/switch.py): `custom_components/sonoff/switch.py`
- [Light entities](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/light.py): `custom_components/sonoff/light.py`
- [Sensor entities](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/sensor.py): `custom_components/sonoff/sensor.py`
- [Climate entities](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/climate.py): `custom_components/sonoff/climate.py`
- [Cover entities](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/cover.py): `custom_components/sonoff/cover.py`
- [Other entity platforms](https://github.com/alexxit/sonofflan/tree/master/custom_components/sonoff): `custom_components/sonoff`

### Special capabilities

- [Camera protocol](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/core/ewelink/camera.py): `custom_components/sonoff/core/ewelink/camera.py`
- [Diagnostics](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/diagnostics.py): `custom_components/sonoff/diagnostics.py`
- [System health](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/system_health.py): `custom_components/sonoff/system_health.py`
- [RF Bridge support](https://github.com/alexxit/sonofflan/blob/master/custom_components/sonoff/remote.py): `custom_components/sonoff/remote.py`

### Other components

- **Home Assistant user**
- **Home Assistant**
- **eWeLink service**
- **Sonoff devices**

## Connections

- Home Assistant user → Config flow: configures
- Config flow → Integration lifecycle: creates entry
- Home Assistant → Integration lifecycle: starts integration
- Integration lifecycle → eWeLink registry: starts registry
- eWeLink registry → Cloud transport: uses cloud
- eWeLink registry → LAN transport: uses LAN
- Cloud transport → eWeLink service: authenticates and fetches
- Cloud transport → eWeLink service: sends commands
- LAN transport → Sonoff devices: discovers and commands
- Sonoff devices → LAN transport: reports state
- eWeLink service → Cloud transport: reports state
- Cloud transport → eWeLink registry: dispatches updates
- LAN transport → eWeLink registry: dispatches updates
- eWeLink registry → Device specifications: selects classes
- eWeLink registry → Entity base: creates entities
- Device specifications → Switch and button: maps devices
- Device specifications → Light entities: maps devices
- Device specifications → Sensor entities: maps devices
- Device specifications → Climate entities: maps devices
- Device specifications → Cover entities: maps devices
- Device specifications → Other entity platforms: maps devices
- Home Assistant → Switch and button: exposes controls
- Home Assistant → Light entities: exposes controls
- Home Assistant → Sensor entities: exposes readings
- Home Assistant → Climate entities: exposes controls
- Home Assistant → Cover entities: exposes controls
- Home Assistant → Other entity platforms: exposes entities
- Switch and button → eWeLink registry: sends commands
- Light entities → eWeLink registry: sends commands
- Climate entities → eWeLink registry: sends commands
- Cover entities → eWeLink registry: sends commands
- eWeLink registry → Switch and button: dispatches state
- eWeLink registry → Light entities: dispatches state
- eWeLink registry → Sensor entities: dispatches state
- eWeLink registry → Climate entities: dispatches state
- eWeLink registry → Cover entities: dispatches state
- Integration lifecycle → Camera protocol: initializes on demand
- Integration lifecycle → RF Bridge support: registers command service
- Home Assistant user → Diagnostics: requests report
- Home Assistant → Diagnostics: provides device data
- Home Assistant → System health: requests status
