Skip to content

haos-eco/smart-gate

Repository files navigation

Smart Gate

GitHub Release Project Stage License

Supports aarch64 Architecture Supports amd64 Architecture

Github Actions Project Maintenance

Development Setup

1. Clone repository

git clone https://github.com/andreaemmanuele/haos_smartgate.git
cd haos_smartgate

2. Install dependencies

pip install -r requirements.txt
pip install -r requirements-test.txt

3. Setup Git hooks (IMPORTANT!)

./setup-hooks.sh

This configures pre-commit hooks to run tests automatically before each commit.


Code Formatting

This project uses Black for Python formatting. All code must be formatted before committing.

Format all files

black .

Format a single file

black app/main.py

Check without modifying (CI-friendly)

black --check .

VS Code integration

Install the Black Formatter extension, then add to .vscode/settings.json:

{
  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnSave": true
  }
}

The pre-commit hook runs black --check . automatically — commits will be rejected if any file is not formatted.


Testing

Run All Tests

Execute the complete test suite:

pytest -v

Run Specific Test File

Test a single module:

# OCR comparison tests (old vs AI SR)
pytest app/tests/test_enhancement_ocr_comparison.py -v

# Image processing tests
pytest app/tests/test_image_processing.py -v

# OCR pattern extraction tests
pytest app/tests/test_ocr.py -v

Run Single Test Function

Execute a specific test with detailed output:

pytest app/tests/test_enhancement_ocr_comparison.py::test_ocr_comparison -v -s

Flags:

  • -v (verbose): Show detailed test names
  • -s: Show print statements and logging output

Run Tests with Coverage

Generate coverage report:

# Terminal output
pytest --cov=. --cov-report=term-missing

# HTML report
pytest --cov=. --cov-report=html
# Open htmlcov/index.html in browser

Run Tests Matching Pattern

Execute tests by name pattern:

# Run all OCR-related tests
pytest -k "ocr" -v

# Run all comparison tests
pytest -k "comparison" -v

Quick Test Commands

# Fast: skip slow tests
pytest -v -m "not slow"

# Debug: stop on first failure
pytest -x

# Watch mode: re-run on file changes (requires pytest-watch)
ptw -- -v

Add Test Images

For OCR comparison tests, add real plate images:

# Copy from Home Assistant
scp root@HA_IP:/config/www/smart_gate/snapshot/debug/last_plate_crop.jpg \
    app/tests/fixtures/plates/sample_plate_GR571XC.png

# Run comparison
pytest app/tests/test_enhancement_ocr_comparison.py::test_ocr_comparison_summary -v -s

Expected output:

======================================================================
Image: sample_plate_GR571XC.png
======================================================================
Expected plate:  GR571XC
Old algorithm:   'CR571XC' (confidence: 0.810)
New AI SR:       'GR571XC' (confidence: 0.967)

Old match: ❌
New match: ✅ IMPROVED

Git Hooks

The pre-commit hook runs black --check . and the full test suite before allowing a commit.

To skip (not recommended):

git commit --no-verify

About

AI Automatic gate opener using YOLO + EasyOCR for license plate recognition.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages