This document provides guidance for developers who want to contribute to or modify the Ghostfolio Home Assistant integration.
- Python 3.11 or higher
- Home Assistant Core 2023.1 or higher
- A running Ghostfolio instance for testing
- Git for version control
git clone <repository-url>
cd ghostfolioYou can develop this integration using one of these approaches:
- Create a
configdirectory in the project root - Copy the
custom_components/ghostfoliodirectory toconfig/custom_components/ghostfolio - Run Home Assistant in a container with the config directory mounted
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=YOUR_TIME_ZONE \
-v $(pwd)/config:/config \
-p 8123:8123 \
ghcr.io/home-assistant/home-assistant:stable- Install Home Assistant Core in a virtual environment
- Symlink the integration to your Home Assistant config directory
python3 -m venv venv
source venv/bin/activate
pip install homeassistant
ln -s $(pwd)/custom_components/ghostfolio ~/.homeassistant/custom_components/ghostfolio- Start Home Assistant
- Go to Settings > Devices & Services > Add Integration
- Search for "Ghostfolio" and configure it with your Ghostfolio instance details
custom_components/ghostfolio/
├── __init__.py # Integration initialization and setup
├── api.py # Ghostfolio API client
├── config_flow.py # Configuration flow for setup/reconfigure
├── const.py # Constants and configuration keys
├── manifest.json # Integration metadata
└── sensor.py # Sensor entities (6 sensors total)
translations/
├── de.json # German translations
├── en.json # English translations
├── fr.json # French translations
└── strings.json # Base translation strings
-
Handles authentication with Ghostfolio (
/api/v1/auth/anonymous) -
get_portfolio_performance: Fetches total or per-account performance -
get_accounts: Fetches list of accounts and base currency settings -
get_holdings: Fetches individual asset data per account
The integration now creates three distinct types of sensors, controlled by configuration options:
1. Global Portfolio Sensors
-
Portfolio Value: Current total market value
-
Portfolio Cost: Total investment amount
-
Portfolio Gain: Absolute net performance
-
Portfolio Gain FX: Absolute net performance with currency effects
-
Simple Gain %: Money-weighted return proxy
(Value - Cost) / Cost -
Time-Weighted Return %: Strategy performance (Ghostfolio standard)
-
Time-Weighted Return FX %: Strategy performance with currency effects
2. Per-Account Sensors Dynamically created for each account (e.g., "ISA", "Trading"):
-
Value: Current market value
-
Cost: Total investment
-
Gain: Absolute gain/loss
-
Simple Gain %: Percentage gain/loss
-
Time-Weighted Return %: Account-specific strategy performance
3. Per-Holding Sensors One sensor created for every asset in your portfolio:
-
State: Total market value in base currency
-
Attributes:
current_price,average_buy_price,number_of_shares,gain_value,gain_pct,trend_vs_buy
-
Show Portfolio Totals: Boolean toggle for global sensors
-
Show Individual Accounts: Boolean toggle for account sensors
-
Show Holdings: Boolean toggle for individual asset sensors
-
Supports re-configuration of these options without reinstalling
- Follow Python PEP 8 style guidelines
- Use type hints for all function parameters and return values
- Add docstrings to all classes and methods
- Use async/await patterns for all I/O operations
- Manual Testing: Use Home Assistant's developer tools to test sensor updates
- Integration Testing: Test with real Ghostfolio instances
- Error Handling: Test with invalid credentials, network issues, etc.
- New Sensors: Add sensor classes in
sensor.pyfollowing the existing pattern - Configuration Options: Add new constants in
const.pyand updateconfig_flow.py - API Endpoints: Extend the
GhostfolioAPIclass inapi.py
- Update
translations/strings.jsonwith new keys - Add translations to
en.json,de.json, andfr.json - Follow the existing translation key structure
Add to your Home Assistant configuration.yaml:
logger:
default: info
logs:
custom_components.ghostfolio: debug- Authentication Errors: Check access token and Ghostfolio URL
- SSL Errors: Verify SSL certificate or disable SSL verification
- Sensor Updates: Check update intervals and API rate limits
Before submitting changes:
- Test with multiple portfolio configurations
- Verify all sensors update correctly
- Test configuration flow (setup and reconfigure)
- Check translations in all supported languages
- Test SSL verification on/off
- Verify error handling for network issues
- Test with invalid credentials
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the development guidelines
- Test thoroughly using the testing checklist
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Home Assistant Developer Documentation
- Home Assistant Custom Integration Tutorial
- Ghostfolio API Documentation
- aiohttp Documentation
For development questions or issues:
- Check existing GitHub issues
- Review Home Assistant logs with debug logging enabled
- Test with a minimal configuration to isolate issues
- Create a detailed issue report with logs and configuration details