# petrleocompel/hikaxpro_hacs architecture

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

- Interactive diagram: https://gitdiagram.com/petrleocompel/hikaxpro_hacs
- Repository: https://github.com/petrleocompel/hikaxpro_hacs

## Overview

##### Main Components

a) External Systems:
- Hikvision AX Pro/Hub Hardware
- Various Supported Sensors (PIR, Magnetic, Temperature, etc.)

b) Integration Components:
- Home Assistant Core
- HACS (Home Assistant Community Store)
- Hikvision AX Pro Custom Component

##### Device Layer
- Hikvision AX Pro/Hub Controller
- Connected Sensors/Detectors

##### Communication Layer
- XML-based API Communication (evident from xmlBuilder.py)
- Authentication/Security Layer (indicated by sha256.py)

##### Integration Layer
- Core Integration Components:
- Config Flow (config_flow.py)
- Main Integration Logic (__init__.py)
- Entity Components:
- Alarm Control Panel
- Sensors
- Switches

##### Home Assistant Layer
- Home Assistant Core
- HACS Integration

##### Specific Implementation Details

Key components:

a) HikAX Client Library (hikax folder):
- Session Management
- Authentication
- API Communication
- Error Handling

b) Entity Components:
- Alarm Control Panel
- Sensors
- Switches

##### Device-to-Integration Communication
- Sensor data flow
- Control commands
- Status updates

##### Integration-to-Home Assistant Communication
- Entity state updates
- Service calls
- Configuration changes

##### Important Elements to Highlight

- Authentication flow
- State management
- Multi-language support (translations folder)
- Configuration flow
- Service definitions
- Entity management

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef hacore fill:#2196F3,color:white
    classDef hardware fill:#4CAF50,color:white
    classDef integration fill:#FFC107,color:black
    classDef security fill:#F44336,color:white
    classDef api fill:#9C27B0,color:white
    classDef entity fill:#FF9800,color:black

    %% Legend
    subgraph Legend
        L1[Home Assistant]:::hacore
        L2[Hardware Components]:::hardware
        L3[Integration Components]:::integration
        L4[Security Components]:::security
        L5[API Components]:::api
        L6[Entity Components]:::entity
    end

    %% Home Assistant Layer
    subgraph "Home Assistant Layer"
        HA[Home Assistant Core]:::hacore
        HACS[HACS]:::hacore
    end

    %% Integration Layer
    subgraph "Integration Layer"
        INIT[Main Integration Logic]:::integration
        CONFIG[Configuration Flow]:::integration
        CONST[Constants & Config]:::integration
        SERVICES[Services Definition]:::integration
        TRANS[Multi-language Support]:::integration
    end

    %% Entity Components
    subgraph "Entity Components"
        ALARM[Alarm Control Panel]:::entity
        SENSOR[Sensors]:::entity
        SWITCH[Switches]:::entity
    end

    %% Communication Layer
    subgraph "Communication Layer"
        XML[XML Builder]:::api
        AUTH[Authentication]:::security
        SESSION_LOGIN[Session Login]:::security
        SESSION_CAP[Session Capabilities]:::security
        ERROR[Error Handling]:::api
    end

    %% Device Layer
    subgraph "Device Layer"
        AXPRO[Hikvision AX Pro Hub]:::hardware
        PIR[PIR Sensors]:::hardware
        MAG[Magnetic Sensors]:::hardware
        TEMP[Temperature Sensors]:::hardware
    end

    %% Relationships
    HA --> HACS
    HACS --> INIT
    INIT --> CONFIG
    INIT --> CONST
    INIT --> SERVICES
    INIT --> TRANS
    
    CONFIG --> AUTH
    CONFIG --> SESSION_LOGIN
    
    INIT --> ALARM
    INIT --> SENSOR
    INIT --> SWITCH
    
    ALARM --> XML
    SENSOR --> XML
    SWITCH --> XML
    
    XML --> SESSION_LOGIN
    XML --> SESSION_CAP
    XML --> ERROR
    
    SESSION_LOGIN --> AUTH
    SESSION_CAP --> AUTH
    
    AUTH --> AXPRO
    
    AXPRO --> PIR
    AXPRO --> MAG
    AXPRO --> TEMP

    %% Click Events
    click INIT "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/__init__.py"
    click CONFIG "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/config_flow.py"
    click AUTH "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/hikax/helpers/sha256.py"
    click XML "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/hikax/helpers/xmlBuilder.py"
    click SESSION_LOGIN "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/hikax/models/SessionLogin.py"
    click SESSION_CAP "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/hikax/models/SessionLoginCap.py"
    click ALARM "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/alarm_control_panel.py"
    click SENSOR "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/sensor.py"
    click SWITCH "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/switch.py"
    click TRANS "https://github.com/petrleocompel/hikaxpro_hacs/tree/master/custom_components/hikvision_axpro/translations"
    click SERVICES "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/services.yaml"
    click CONST "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/const.py"
    click ERROR "https://github.com/petrleocompel/hikaxpro_hacs/blob/master/custom_components/hikvision_axpro/hikax/errors/errors.py"
```
