RepoPilot

home-assistant / core

Search home-assistant/core

GitHub

Code

Understand home-assistant/core's source layout and find a starting point for your task using the saved repository evidence.

Detailed import-graph metrics were not captured for this report.

How the code fits together

AI
  • Core & BootstrapApplication initialization, runtime setup, and main event loop management.
  • Authentication & AuthorizationUser management, credential validation, multi-factor authentication, and permission-based access control.
  • Data & PersistenceBackup, restoration, state management, and configuration persistence.
  • Brand & Integration MetadataBrand assets, logos, and integration discovery metadata.

Files at fc43ebe75757 · descriptions are AI-written.

The descriptions and the file list come from different revisions. Check responsibilities against source.

Where to start reading

  1. Repository root
  2. Repository root
  3. Runtime candidatename match
  4. Suggested starting pointAI
  5. Suggested starting pointAI

Find files for a task

AI

Add a New Authentication Provider

Suggested by the saved analysis. Verify the proposed change against these source files.

  • Create a new module in homeassistant/auth/providers/ inheriting from the provider base class.
  • Implement async_validate_login() and async_get_or_create_user() methods following existing provider patterns (e.g., homeassistant.py, trusted_networks.py).
  • Register the provider in auth/__init__.py by adding it to the provider lookup dictionary.

Add a New Multi-Factor Authentication Module

Suggested by the saved analysis. Verify the proposed change against these source files.

  • Create a new module in homeassistant/auth/mfa_modules/ implementing the MFA module interface.
  • Implement async_validate() to validate MFA codes and async_is_enabled() to check module status.
  • Register the module in auth/__init__.py MFA module discovery.

Add a New Permission Type

Suggested by the saved analysis. Verify the proposed change against these source files.

  • Define permission constants and policies in homeassistant/auth/permissions/const.py.
  • Implement permission checker in homeassistant/auth/permissions/ (e.g., entities.py, events.py) following existing patterns.
  • Register permission checker in homeassistant/auth/permissions/__init__.py permission resolution pipeline.
  • Add system policies in homeassistant/auth/permissions/system_policies.py if applicable.

Change the public API

Start with possible export surfaces, then check their consumers and tests. These suggestions use file names, not verified execution paths.

  • File-name match for this task.
  • File-name match for this task.
  • File-name match for this task.

Trace runtime behavior

Start with possible startup or request handlers, then follow the calls for your scenario. These suggestions use file names, not verified execution paths.

  • File-name match for this task.

Add or update tests

Use a nearby test as a pattern. Read the root manifest or contribution guide for the correct test command. These suggestions use file names, not verified execution paths.

  • File-name match for this task.
  • File-name match for this task.
  • File-name match for this task.

Change build or automation

Inspect the relevant configuration and the commands it runs before changing the workflow. These suggestions use file names, not verified execution paths.

  • File-name match for this task.
  • File-name match for this task.
  • File-name match for this task.

File paths come from a snapshot of up to 500 captured paths; an omitted file may still exist.

  • Public and runtime candidates are based on file names; their exports and execution paths still need checking in source.
  • The file list was refreshed after the written analysis. Subsystem descriptions and suggested changes may describe an older revision.

Architecture and request flow

Start here — files every contributor must understand

AI · unverified
1
homeassistant/__init__.py

Core Home Assistant initialization and main API surface; entry point for understanding the framework's structure.

2
homeassistant/__main__.py

Application entrypoint that bootstraps the Home Assistant runtime and event loop.

3
homeassistant/bootstrap.py

Startup orchestration for loading components, integrations, and configuration; critical for understanding initialization order.

4
homeassistant/auth/__init__.py

Authentication framework providing user, permission, and credential management across the system.

5
homeassistant/auth/permissions/__init__.py

Permission model and access control layer that gates entity, event, and system-level operations.

6
homeassistant/backup_restore.py

Backup and restoration pipeline; critical for data persistence and recovery workflows.

7
homeassistant/block_async_io.py

Async/sync boundary enforcement preventing blocking calls in async contexts; enforces architectural compliance.

Request flow

Technology choices

Async/await (Python asyncio)

Enables non-blocking I/O for handling multiple device connections and automations concurrently without thread overhead.

Modular component system

Allows independent development and distribution of integrations for different device brands and services without monolithic core changes.

JWT-based authentication

Provides stateless token-based authentication suitable for distributed home automation deployments and API-first architecture.

Permission-based access control (PBAC)

Enables fine-grained authorization for entity and event access, supporting multi-user household scenarios with restricted access levels.

Build time and runtime

Build-time

  • ▸
    Component discovery and registration — Scan and load component manifests from homeassistant/auth/, homeassistant/brands/, and integration directories.
  • ▸
    Permission schema compilation — Build permission trees from component declarations and system policies.
  • ▸
    Backport imports — Load Python compatibility backports from homeassistant/backports/ for older Python versions.

Runtime

  • ▸
    Event loop and asyncio scheduler — Main concurrency primitive driving async component tasks, timers, and integration callbacks.
  • ▸
    Auth provider validation — Execute pluggable authentication provider logic (credential lookup, MFA validation) on user login.
  • ▸
    Permission enforcement — Check user permissions against entity/event access on every operation; reject unauthorized requests.
  • ▸
    Component lifecycle management — Initialize, configure, and teardown integration instances; manage entity registries and state.
  • ▸
    Backup/restore operations — Serialize and persist configuration, automation, and credential state; restore on startup or manual request.

Design trade-offs

Single-threaded async architecture with blocking I/O guard

Simplifies state consistency and scheduling; prevents race conditions on shared state.

Blocking operations must be deferred to thread pools; CPU-intensive integrations risk event loop starvation.

Local-first with optional cloud connectivity

Prioritizes privacy and local control for core operations.

Remote access and cloud features require additional setup; not all integrations work offline.

Pluggable provider system for authentication and MFA

Allows operators to choose their credential source (local, LDAP, OAuth, etc.).

Adds complexity to auth layer; operators responsible for secure provider implementation.

Non-goals

  • ✗Cloud-first deployment or SaaS-only operation
  • ✗Real-time constraint guarantees for automation execution
  • ✗Machine learning inference at scale on edge devices
  • ✗Multi-tenant isolation at the framework level (designed for single household/organization)

Code quality and hotspots

Quality Score: 90/100

Low Risk

This repo is in good health with CI, tests, and active maintenance.

Multiple anti-patterns -10

Maintainability grade

Static analysis

How maintainable the code looks — from complexity, code issues, test presence, file size, and hotspot load. It grades the shape of the code, not defect risk, and doesn't replace review.

A
88/100
A ≥ 85, B ≥ 70, C ≥ 55, D ≥ 40, F < 40
Cyclomatic complexityavg 11
30/35
Code issues0 errors, 4 warnings
19/20
Testspresent · ~100% of files
20/20
Largest file1,114 lines
11/15
Hotspot load1 high-risk file
8/10

Configuration status

CI/CD Pipeline — configured

Provider: GitHub Actions

15 GitHub Actions workflows

Test Suite — detected

13,772 test files detected

Stack: Pytest

Where: pylint/plugins/pylint_home_assistant/checkers/tests · tests/auth/mfa_modules · tests/auth/permissions

Test Coverage — ~100%heuristic

13,772 test files / 10,693 source files. This is a file-count ratio, not real line coverage — set up Codecov for authoritative numbers.

Dependency Scanning — 1 tool configured

CodeQL

Top hotspots

Files edited often AND hard to reason about. Churn = recent commit frequency, Complexity = branches and nesting, Risk = both combined. These are the highest-leverage targets for refactoring or testing.

homeassistant/bootstrap.py
Churn: 60 (15 commits/180d)Complexity: 100Risk: 60
airos/config_flow.py
Churn: 24 (6 commits/180d)Complexity: 48Risk: 12

All hotspots

Files that change often and are complex tend to accumulate more bugs

AI-suggested anti-patterns

AI · unverified

Pattern-matches from the file structure and dependencies — useful as hypotheses, but not grounded in actual source. For real findings see Code Scanning above.

Mixed synchronous/asynchronous boundaries without enforcement

High

Auth providers and permission checkers may accidentally call blocking operations; block_async_io guard attempts detection but relies on runtime behavior rather than static typing.

homeassistant/block_async_io.py and auth subsystem

Hardcoded auth provider list without discoverable registry

Medium

Adding new auth providers requires modifying core auth module rather than using plugin/entry point system; scales poorly.

homeassistant/auth/providers/__init__.py

Monolithic permission schema in system_policies.py

Medium

All default policies centralized in single file; makes it difficult for integrations to define custom permission types without core changes.

homeassistant/auth/permissions/system_policies.py

Implicit permission merging in merge.py without conflict resolution strategy

Medium

Permission merging logic may produce unexpected results when multiple policies conflict; no clear precedence rules.

homeassistant/auth/permissions/merge.py

AI-suggested bottlenecks

AI · unverified

Speculation from file structure, not profiling data. Validate against real metrics before acting on these.

I/O and CPU Bottleneck

Sequential credential lookups and JSON deserialization on every login; no caching or indexing of user credentials.

homeassistant/auth/auth_store.py

CPU Bottleneck

Permission resolution traverses full permission tree for every entity/event access check; no caching of computed permissions per user.

homeassistant/auth/permissions/__init__.py

Startup time Bottleneck

Sequential component and integration loading during startup; no parallel initialization of independent components.

homeassistant/bootstrap.py

I/O and disk space Bottleneck

Full state serialization and disk write on every backup; no incremental or differential backup support.

homeassistant/backup_restore.py

Code metrics

Static analysis on sampled source files (up to 15 files).

Avg Cyclomatic Complexity11

Counts if/for/while/switch/catch/ternary branches

Errors / Warnings0 / 4

Secrets, empty catches, console.log, var usage, long lines

Largest File Analyzed1114 lines
homeassistant/bootstrap.py