Thank you for your interest in contributing to the Portainer Home Assistant integration!
# 1. Clone and enter directory
git clone https://github.com/tomaae/homeassistant-portainer.git
cd homeassistant-portainer
# 2. Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# or
.venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements_test.txt
# 4. Run tests to verify setup
python -m pytest -vThis project uses Black for consistent code formatting. All code must be Black-formatted before submitting.
# Format all Python files
black custom_components/ tests/
# Check if files need formatting (dry run)
black --check custom_components/ tests/
# Format specific file
black custom_components/portainer/coordinator.py
# Show what would change without applying
black --diff custom_components/ tests/Configuration: Black uses default settings (88 character line length, etc.)
VS Code Integration: The provided .vscode/settings.json enables auto-formatting on save.
- Line length: 88 characters (Black default)
- Follow PEP 8 conventions
- Use meaningful variable and function names
- Write tests for all new functionality
- Maintain 100% test success rate
- Use descriptive test names and docstrings
- Current test coverage: 55 tests (37 tag parsing + 18 update logic)
- Use type hints for all function parameters and return values
- Import types from
typingmodule when needed
- Update README.md for user-facing changes
- Add docstrings to all public methods
- Use clear, descriptive variable names
# All tests
python -m pytest
# Specific test file
python -m pytest tests/test_tag_parsing.py
# With coverage
python -m pytest --cov=custom_components.portainer --cov-report=htmltests/test_tag_parsing.py: Docker image name parsing logictests/test_update_checks.py: Container update check functionality
- Place tests in appropriate file based on functionality
- Use descriptive test class and method names
- Include docstrings explaining what the test validates
- Use pytest fixtures for common setup
- Mock external dependencies (API calls, Home Assistant core)
- Fork the repository
- Create feature branch:
git checkout -b feature/your-feature-name - Make changes with tests
- Format code:
black custom_components/ tests/(required!) - Run tests:
python -m pytest(must pass!) - Commit:
git commit -m "Add your feature description" - Push:
git push origin feature/your-feature-name - Create Pull Request
Before committing, ensure:
- Code is Black-formatted:
black --check custom_components/ tests/ - All tests pass:
python -m pytest - No linting errors
- Documentation updated if needed
- Clear description of changes
- Reference any related issues
- Ensure all tests pass
- Update documentation if needed
- Add tests for new functionality
- Python (ms-python.python)
- Black Formatter (ms-python.black-formatter)
- Pylint (ms-python.pylint)
- GitLens (eamodio.gitlens)
pip install pre-commit
pre-commit installThis will automatically format code and run basic checks before each commit.
coordinator.py: Main data coordinator handling API communicationsensor.py: Container sensor entitiesbutton.py: Container action buttons (start/stop/restart)config_flow.py: Integration setup flow
- Docker Image Tag Parsing: Complex registry/tag parsing logic
- Update Check Logic: Container update detection and caching
- API Communication: Portainer API integration
- Error Handling: Graceful handling of API failures
- Issues: Use GitHub Issues for bug reports and feature requests
- Discussions: Use GitHub Discussions for questions and ideas
- Documentation: Check README.md and inline code documentation
Please be respectful and constructive in all interactions. This project follows the standard open source community guidelines.