Contributing¶
Thank you for your interest in contributing to the AutoPi Home Assistant integration! This guide will help you get started with contributing to the project.
Ways to Contribute¶
π Bug Reports¶
Help us improve by reporting bugs you encounter:
- Search existing issues before creating new ones
- Use issue templates for consistent reporting
- Provide detailed information including logs and steps to reproduce
- Test with latest version to ensure the bug still exists
π‘ Feature Requests¶
Suggest new features or improvements:
- Check existing requests to avoid duplicates
- Describe the use case and how it would benefit users
- Consider implementation complexity and AutoPi API capabilities
- Be open to discussion about the best approach
π Documentation¶
Improve documentation for users and developers:
- Fix typos and errors in existing documentation
- Add missing information or clarify confusing sections
- Create examples and tutorials
- Translate documentation to other languages
π» Code Contributions¶
Contribute code improvements and new features:
- Bug fixes for reported issues
- New features that enhance functionality
- Performance improvements and optimizations
- Test coverage improvements
Getting Started¶
Development Environment¶
- Prerequisites:
- Python 3.11 or later
- Git
- Home Assistant development environment
-
AutoPi account for testing
-
Setup:
-
Verify Setup:
Project Structure¶
autopi-ha/
βββ custom_components/autopi/ # Main integration code
βββ tests/ # Test suite
βββ docs/ # Documentation
βββ scripts/ # Development scripts
βββ .github/ # GitHub workflows
βββ pyproject.toml # Project configuration
βββ Makefile # Development commands
Development Workflow¶
1. Choose an Issue¶
- Browse open issues on GitHub
- Look for "good first issue" labels for beginners
- Ask questions if you need clarification
- Assign yourself to avoid duplicate work
2. Create a Branch¶
# Create and switch to a new branch
git checkout -b feature/your-feature-name
# Or for bug fixes
git checkout -b fix/issue-description
3. Make Changes¶
Code Guidelines¶
- Follow existing patterns in the codebase
- Use type hints throughout your code
- Add docstrings to classes and functions
- Keep functions focused and single-purpose
- Handle errors gracefully with appropriate exceptions
Example Code Style¶
class ExampleSensor(AutoPiVehicleEntity, SensorEntity):
"""Example sensor for demonstration.
This sensor shows how to implement a new vehicle sensor
following the project's conventions.
"""
_attr_icon = "mdi:example"
_attr_device_class = SensorDeviceClass.TEMPERATURE
def __init__(
self,
coordinator: AutoPiDataUpdateCoordinator,
vehicle_id: str,
) -> None:
"""Initialize the example sensor.
Args:
coordinator: The data coordinator
vehicle_id: The vehicle ID
"""
super().__init__(coordinator, vehicle_id, "example")
self._attr_name = "Example"
@property
def native_value(self) -> float | None:
"""Return the sensor value."""
if vehicle := self.vehicle:
return vehicle.example_data
return None
4. Write Tests¶
All code changes should include appropriate tests:
async def test_example_sensor(hass, mock_coordinator):
"""Test example sensor functionality."""
# Arrange
sensor = ExampleSensor(mock_coordinator, "test_vehicle")
# Act
await sensor.async_update()
# Assert
assert sensor.native_value == expected_value
5. Update Documentation¶
- Update docstrings for new or changed code
- Add user documentation for new features
- Update changelog for notable changes
- Run documentation generation:
6. Test Your Changes¶
# Run all tests
uv run pytest
# Run specific tests
uv run pytest tests/test_sensor.py
# Run with coverage
uv run pytest --cov=custom_components.autopi
# Test with real Home Assistant
cp -r custom_components/autopi /path/to/ha/config/custom_components/
7. Commit Changes¶
# Stage your changes
git add .
# Commit with descriptive message
git commit -m "feat: add example sensor for vehicle data
- Implement ExampleSensor class
- Add tests for sensor functionality
- Update documentation"
Commit Message Format¶
Use conventional commits format:
feat:
for new featuresfix:
for bug fixesdocs:
for documentation changestest:
for test additions/changesrefactor:
for code refactoringchore:
for maintenance tasks
8. Push and Create Pull Request¶
# Push your branch
git push origin feature/your-feature-name
# Create pull request on GitHub
# Fill out the PR template with details
Pull Request Guidelines¶
PR Requirements¶
- Clear description of changes and motivation
- Tests included for new functionality
- Documentation updated as needed
- All checks passing (tests, linting, etc.)
- No breaking changes without discussion
PR Template¶
## Description
Brief description of what this PR does.
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Refactoring
## Testing
- [ ] Tests added/updated
- [ ] Manual testing completed
- [ ] All checks passing
## Checklist
- [ ] Code follows project style
- [ ] Documentation updated
- [ ] Changelog updated
Review Process¶
- Automated checks must pass
- Maintainer review of code and approach
- Testing by maintainers or community
- Feedback incorporation as needed
- Final approval and merge
Coding Standards¶
Code Quality¶
The project uses several tools to maintain code quality:
# Linting with Ruff
uv run ruff check .
uv run ruff format .
# Type checking with MyPy
uv run mypy custom_components
# Security scanning with Bandit
uv run bandit -r custom_components
Testing Standards¶
- Unit tests for individual components
- Integration tests for component interaction
- Mock external dependencies (don't call real APIs)
- Aim for >90% coverage on new code
- Test error conditions and edge cases
Documentation Standards¶
- Docstrings for all public classes and methods
- Type hints throughout the codebase
- User documentation for new features
- Code comments for complex logic
- Examples for usage patterns
Specific Contribution Areas¶
π Adding New Sensors¶
- Identify data source in AutoPi API
- Design sensor class extending base entities
- Implement data fetching in coordinator
- Add tests for sensor behavior
- Update documentation with new sensor info
πΊοΈ Improving Device Tracking¶
- Enhance GPS accuracy handling
- Add location features (zones, geocoding)
- Optimize update frequency based on movement
- Implement geofencing capabilities
π API Optimization¶
- Reduce API calls through better caching
- Implement smart scheduling based on usage
- Add connection pooling improvements
- Enhance error recovery mechanisms
π§ͺ Testing Improvements¶
- Add integration tests with Home Assistant
- Mock more API scenarios for thorough testing
- Performance testing for large fleets
- User acceptance testing scenarios
Community Guidelines¶
Code of Conduct¶
- Be respectful and inclusive in all interactions
- Provide constructive feedback in reviews
- Help newcomers get started with contributions
- Follow GitHub community guidelines
Communication¶
- Use GitHub issues for bug reports and feature requests
- Join discussions on existing issues before starting work
- Ask questions if you're unsure about implementation
- Provide updates on work in progress
Recognition¶
Contributors are recognized in:
- Changelog for notable contributions
- GitHub contributors section
- Release notes for major features
- Documentation acknowledgments
Development Resources¶
Useful Links¶
- Home Assistant Developer Docs: Core development guide
- AutoPi API Docs: API reference
- Python Type Hints: Type annotation guide
- Pytest Documentation: Testing framework
Development Tools¶
# Makefile commands
make help # Show available commands
make test # Run tests
make lint # Run linting
make format # Format code
make check-all # Run all checks
make docgen # Generate documentation
Debugging Tips¶
-
Enable debug logging:
-
Use VS Code debugger with Home Assistant
- Test with mock data before real API calls
- Check entity registry for proper registration
Release Process¶
Version Bumping¶
- Update version in
manifest.json
- Update changelog with new features
- Create release with GitHub Actions
- Test release with HACS installation
Release Types¶
- Patch releases (0.1.1): Bug fixes, minor improvements
- Minor releases (0.2.0): New features, non-breaking changes
- Major releases (1.0.0): Breaking changes, major features
Getting Help¶
Where to Get Help¶
- GitHub Discussions: General questions and ideas
- GitHub Issues: Specific bugs or feature requests
- Code Comments: In-line questions during review
- Documentation: Comprehensive guides and references
Maintainer Response¶
- Issues: Usually within 1-3 days
- Pull Requests: Review within 1 week
- Questions: Best effort response
- Security Issues: Immediate attention
Thank you for contributing to the AutoPi Home Assistant integration! Your contributions help make the project better for everyone. πβ¨