# felipeheuer/energy_guard architecture

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

- Interactive diagram: https://gitdiagram.com/felipeheuer/energy_guard
- Repository: https://github.com/felipeheuer/energy_guard

## Overview

Energy Guard is a Home Assistant integration that configures controllable devices as virtual circuit breakers. The user selects eligible devices and their power sensors; setup creates per-device entities, whose monitoring logic normalizes readings, applies a limit and delay, raises alerts, and can turn off the device. Configuration controls and persistent peak/trip statistics round out the workflow. The source excerpts show these core calls and event links; broader Home Assistant platform behavior is represented only where documented or directly referenced.

Main entry points: [`custom_components/energy_guard/binary_sensor.py`](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/binary_sensor.py) (Alert and trip logic), [`custom_components/energy_guard/__init__.py`](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/__init__.py) (Entry setup), [`custom_components/energy_guard/config_flow.py`](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/config_flow.py) (Device selection), [`custom_components/energy_guard/sensor.py`](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/sensor.py) (Peak and trip sensors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Configuration"]
  node_config_flow["Device selection<br/>[config_flow.py]"]
  node_setup_entry["Entry setup<br/>[__init__.py]"]
  node_defaults["Shared constants<br/>[const.py]"]
end

subgraph group_runtime["Monitoring"]
  node_alert["Alert and trip logic<br/>[binary_sensor.py]"]
end

subgraph group_controls["Controls"]
  node_number_controls["Limit and delay<br/>[number.py]"]
  node_switch_controls["Monitor and cutoff<br/>[switch.py]"]
  node_reset_button["Reset stats button<br/>[button.py]"]
end

subgraph group_stats["Diagnostics"]
  node_diagnostic_sensors["Peak and trip sensors<br/>[sensor.py]"]
end

node_user(("Home Assistant user"))
node_registries[("Device and entity registries")]
node_power["Power sensor entities"]
node_physical_switch["Device switch"]
node_event_bus["Home Assistant event bus"]
node_ha_entities["Home Assistant entities"]

node_user -->|"selects devices"| node_config_flow
node_config_flow -->|"discovers devices"| node_registries
node_config_flow -->|"saves selection"| node_setup_entry
node_setup_entry -->|"resolves devices"| node_registries
node_setup_entry -->|"forwards platforms"| node_ha_entities
node_setup_entry -->|"uses platform list"| node_defaults
node_alert -->|"reads power state"| node_power
node_alert -->|"reads limit and delay"| node_number_controls
node_alert -->|"reads monitor and cutoff"| node_switch_controls
node_alert -->|"fires trip events"| node_event_bus
node_alert -->|"turns off on trip"| node_physical_switch
node_reset_button -->|"fires reset event"| node_event_bus
node_diagnostic_sensors -->|"tracks peak readings"| node_power
node_diagnostic_sensors -->|"listens for trip and reset"| node_event_bus

click node_config_flow "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/config_flow.py"
click node_setup_entry "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/__init__.py"
click node_defaults "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/const.py"
click node_alert "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/binary_sensor.py"
click node_number_controls "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/number.py"
click node_switch_controls "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/switch.py"
click node_reset_button "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/button.py"
click node_diagnostic_sensors "https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/sensor.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_flow,node_setup_entry,node_defaults,node_user toneBlue
class node_alert,node_registries toneAmber
class node_number_controls,node_switch_controls,node_reset_button toneMint
class node_diagnostic_sensors toneRose
class node_power,node_physical_switch,node_event_bus,node_ha_entities toneIndigo
```

## Components

### Configuration

- [Device selection](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/config_flow.py): `custom_components/energy_guard/config_flow.py`
- [Entry setup](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/__init__.py): `custom_components/energy_guard/__init__.py`
- [Shared constants](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/const.py): `custom_components/energy_guard/const.py`

### Monitoring

- [Alert and trip logic](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/binary_sensor.py): `custom_components/energy_guard/binary_sensor.py`

### Controls

- [Limit and delay](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/number.py): `custom_components/energy_guard/number.py`
- [Monitor and cutoff](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/switch.py): `custom_components/energy_guard/switch.py`
- [Reset stats button](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/button.py): `custom_components/energy_guard/button.py`

### Diagnostics

- [Peak and trip sensors](https://github.com/felipeheuer/energy_guard/blob/main/custom_components/energy_guard/sensor.py): `custom_components/energy_guard/sensor.py`

### Other components

- **Home Assistant user**
- **Device and entity registries**
- **Power sensor entities**
- **Device switch**
- **Home Assistant event bus**
- **Home Assistant entities**

## Connections

- Home Assistant user → Device selection: selects devices (evidence: `README.md`)
- Device selection → Device and entity registries: discovers devices (evidence: `custom_components/energy_guard/config_flow.py`)
- Device selection → Entry setup: saves selection (evidence: `custom_components/energy_guard/config_flow.py`)
- Entry setup → Device and entity registries: resolves devices (evidence: `custom_components/energy_guard/__init__.py`)
- Entry setup → Home Assistant entities: forwards platforms (evidence: `custom_components/energy_guard/__init__.py`)
- Entry setup → Shared constants: uses platform list (evidence: `custom_components/energy_guard/__init__.py`)
- Alert and trip logic → Power sensor entities: reads power state (evidence: `custom_components/energy_guard/binary_sensor.py`)
- Alert and trip logic → Limit and delay: reads limit and delay (evidence: `custom_components/energy_guard/binary_sensor.py`)
- Alert and trip logic → Monitor and cutoff: reads monitor and cutoff (evidence: `custom_components/energy_guard/binary_sensor.py`)
- Alert and trip logic → Home Assistant event bus: fires trip events (evidence: `custom_components/energy_guard/binary_sensor.py`)
- Alert and trip logic → Device switch: turns off on trip (evidence: `custom_components/energy_guard/binary_sensor.py`)
- Reset stats button → Home Assistant event bus: fires reset event (evidence: `custom_components/energy_guard/button.py`)
- Peak and trip sensors → Power sensor entities: tracks peak readings (evidence: `custom_components/energy_guard/sensor.py`)
- Peak and trip sensors → Home Assistant event bus: listens for trip and reset (evidence: `custom_components/energy_guard/sensor.py`)
