This document contains technical information for developers who want to contribute to or modify the Area Occupancy Detection integration.
- Python 3.10 or higher
- Home Assistant development environment
- Git
- Visual Studio Code (recommended)
- Docker (optional, for container-based development)
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS .\venv\Scripts\activate # Windows
-
Install development dependencies:
pip install -r requirements.dev.txt
-
Install pre-commit hooks:
pre-commit install
custom_components/area_occupancy/
├── __init__.py # Integration initialization
├── manifest.json # Integration metadata
├── const.py # Constants and configuration
├── config_flow.py # Configuration UI
├── coordinator.py # Data update coordinator
├── calculations.py # Bayesian calculations
├── base.py # Base entity classes
├── sensor.py # Probability sensor
├── binary_sensor.py # Occupancy sensor
├── strings.json # String resources
└── translations/ # Localization
└── en.json # English translations
coordinator.py
: Manages sensor updates and schedulingcalculations.py
: Handles Bayesian probability calculationsbase.py
: Provides shared entity functionalitysensor.py
/binary_sensor.py
: Entity implementations
AreaOccupancyCoordinator
: Manages data updates and sensor state trackingProbabilityCalculator
: Implements Bayesian probability calculationsAreaOccupancySensorBase
: Base class for sensor entitiesAreaOccupancyConfigFlow
: Handles UI configuration
# Run all tests
pytest
# Run specific test file
pytest tests/test_sensor.py
# Run with coverage
pytest --cov=custom_components.area_occupancy
tests/
├── conftest.py # Test fixtures
├── test_init.py # Integration tests
├── test_config_flow.py # Configuration tests
├── test_coordinator.py # Coordinator tests
└── test_sensor.py # Entity tests
- Follow Home Assistant's style guide
- Use
black
for code formatting - Use
isort
for import sorting - Maintain pylint score above 9/10
- Fork the repository
- Create feature branch from
dev
- Write tests for new functionality
- Update documentation
- Submit PR against
dev
branch - Ensure all checks pass
logger:
default: info
logs:
custom_components.area_occupancy: debug
- Open in VS Code with Remote Containers extension
- Select "Reopen in Container"
- Use provided debug configurations
The integration uses Bayesian probability with:
- Prior probability based on historical data
- Likelihood calculations for each sensor type
- Weighted sensor contributions
- Time-based decay of sensor readings
- Coordinator manages sensor state updates
- Historical data stored in rolling windows
- Decay implemented using configurable time windows
- Sensor availability tracking and fallback
- UI-based configuration using config flows
- Dynamic validation of sensor entities
- Runtime configuration updates
- Options flow for post-install modification
- Limited historical data storage
- Efficient state tracking
- Cleanup of unused data
- Optimized calculation frequency
- Caching of intermediate results
- Batched sensor updates
-
Version Management
- Update
manifest.json
version - Update
CHANGELOG.md
- Create release tag
- Update
-
Testing
- Run full test suite
- Perform manual testing
- Test upgrade path
-
Documentation
- Update documentation
- Update example configurations
-
Release
- Create GitHub release
- Update HACS repository
- Input validation on all configuration
- Sensor state verification
- Proper error handling
- Secure default values