Developer Documentation
This section contains documentation for contributors and maintainers of the Tibber Prices custom integration.
This is an independent, community-maintained custom integration for Home Assistant. It is not an official Tibber product and is not affiliated with Tibber AS.
๐ Developer Guidesโ
- Setup - DevContainer, environment setup, and dependencies
- Architecture - Code structure, patterns, and conventions
- Period Calculation Theory - Mathematical foundations, Flex/Distance interaction, Relaxation strategy
- Timer Architecture - Timer system, scheduling, coordination (3 independent timers)
- Caching Strategy - Cache layers, invalidation, debugging
- Testing - How to run tests and write new test cases
- Release Management - Release workflow and versioning process
- Coding Guidelines - Style guide, linting, and best practices
- Refactoring Guide - How to plan and execute major refactorings
๐ค AI Documentationโ
The main AI/Copilot documentation is in AGENTS.md. This file serves as long-term memory for AI assistants and contains:
- Detailed architectural patterns
- Code quality rules and conventions
- Development workflow guidance
- Common pitfalls and anti-patterns
- Project-specific patterns and utilities
Important: When proposing changes to patterns or conventions, always update AGENTS.md to keep AI guidance consistent.
AI-Assisted Developmentโ
This integration is developed with extensive AI assistance (GitHub Copilot, Claude, and other AI tools). The AI handles:
- Pattern Recognition: Understanding and applying Home Assistant best practices
- Code Generation: Implementing features with proper type hints, error handling, and documentation
- Refactoring: Maintaining consistency across the codebase during structural changes
- Translation Management: Keeping 5 language files synchronized
- Documentation: Generating and maintaining comprehensive documentation
Quality Assurance:
- Automated linting with Ruff (120-char line length, max complexity 25)
- Home Assistant's type checking and validation
- Real-world testing in development environment
- Code review by maintainer before merging
Benefits:
- Rapid feature development while maintaining quality
- Consistent code patterns across all modules
- Comprehensive documentation maintained alongside code
- Quick bug fixes with proper understanding of context
Limitations:
- AI may occasionally miss edge cases or subtle bugs
- Some complex Home Assistant patterns may need human review
- Translation quality depends on AI's understanding of target language
- User feedback is crucial for discovering real-world issues
If you're working with AI tools on this project, the AGENTS.md file provides the context and patterns that ensure consistency.
๐ Quick Start for Contributorsโ
- Fork and clone the repository
- Open in DevContainer (VS Code: "Reopen in Container")
- Run setup:
./scripts/setup/setup(happens automatically viapostCreateCommand) - Start development environment:
./scripts/develop - Make your changes following the Coding Guidelines
- Run linting:
./scripts/lint - Validate integration:
./scripts/release/hassfest - Test your changes in the running Home Assistant instance
- Commit using Conventional Commits format
- Open a Pull Request with clear description
๐ ๏ธ Development Toolsโ
The project includes several helper scripts in ./scripts/:
bootstrap- Initial setup of dependenciesdevelop- Start Home Assistant in debug mode (auto-cleans .egg-info)clean- Remove build artifacts and cacheslint- Auto-fix code issues with rufflint-check- Check code without modifications (CI mode)hassfest- Validate integration structure (JSON, Python syntax, required files)setup- Install development tools (git-cliff, @github/copilot)prepare-release- Prepare a new release (bump version, create tag)generate-release-notes- Generate release notes from commits
๐ฆ Project Structureโ
custom_components/tibber_prices/
โโโ __init__.py # Integration setup
โโโ coordinator.py # Data update coordinator with caching
โโโ api.py # Tibber GraphQL API client
โโโ price_utils.py # Price enrichment functions
โโโ average_utils.py # Average calculation utilities
โโโ sensor/ # Sensor platform (package)
โ โโโ __init__.py # Platform setup
โ โโโ core.py # TibberPricesSensor class
โ โโโ definitions.py # Entity descriptions
โ โโโ helpers.py # Pure helper functions
โ โโโ attributes.py # Attribute builders
โโโ binary_sensor.py # Binary sensor platform
โโโ entity_utils/ # Shared entity helpers
โ โโโ icons.py # Icon mapping logic
โ โโโ colors.py # Color mapping logic
โ โโโ attributes.py # Common attribute builders
โโโ services.py # Custom services
โโโ config_flow.py # UI configuration flow
โโโ const.py # Constants and helpers
โโโ translations/ # Standard HA translations
โโโ custom_translations/ # Extended translations (descriptions)
๐ Key Conceptsโ
DataUpdateCoordinator Pattern:
- Centralized data fetching and caching
- Automatic entity updates on data changes
- Persistent storage via
Store - Quarter-hour boundary refresh scheduling
Price Data Enrichment:
- Raw API data is enriched with statistical analysis
- Trailing/leading 24h averages calculated per interval
- Price differences and ratings added
- All via pure functions in
price_utils.py
Translation System:
- Dual system:
/translations/(HA schema) +/custom_translations/(extended) - Both must stay in sync across all languages (de, en, nb, nl, sv)
- Async loading at integration setup
๐งช Testingโ
# Validate integration structure
./scripts/release/hassfest
# Run all tests
pytest tests/
# Run specific test file
pytest tests/test_coordinator.py
# Run with coverage
pytest --cov=custom_components.tibber_prices tests/
๐ Documentation Standardsโ
Documentation is organized in two Docusaurus sites:
- User docs (
docs/user/): Installation, configuration, usage guides- Markdown files in
docs/user/docs/*.md - Navigation managed via
docs/user/sidebars.ts
- Markdown files in
- Developer docs (
docs/developer/): Architecture, patterns, contribution guides- Markdown files in
docs/developer/docs/*.md - Navigation managed via
docs/developer/sidebars.ts
- Markdown files in
- AI guidance:
AGENTS.md(patterns, conventions, long-term memory)
Best practices:
- Use clear examples and code snippets
- Keep docs up-to-date with code changes
- Add new pages to appropriate
sidebars.tsfor navigation
๐ค Contributingโ
See CONTRIBUTING.md for detailed contribution guidelines, code of conduct, and pull request process.
๐ Licenseโ
This project is licensed under the MIT License.
Note: This documentation is for developers. End users should refer to the User Documentation.