-
Notifications
You must be signed in to change notification settings - Fork 9
Developer Debugging
Enable debug logging in config/configuration.yaml:
logger:
default: info
logs:
custom_components.adaptive_cover_pro: debugCause: Coordinator not triggering updates
Solution:
- Check if entity is listening to coordinator
- Verify
_handle_coordinator_update()is called - Check coordinator's
async_update_listeners()is called
Cause: Sun position or geometry calculation
Solution:
- Enable diagnostic sensors to see calculated values
- Use Jupyter notebook to visualize calculations
- Check sun position: azimuth, elevation
- Verify window azimuth and field of view
Cause: Threshold or state comparison
Solution:
- Check
manual_override_thresholdsetting - Verify cover entity reports position correctly
- Enable Last Cover Action diagnostic sensor
- Check logs for "Manual override detected" messages
The project includes a complete VS Code debugging environment with pre-configured debug configurations, test integration, linting, and formatting.
Install the recommended VS Code extensions (you'll be prompted when opening the workspace):
- ms-python.python - Core Python support
- ms-python.vscode-pylance - Advanced IntelliSense and type checking
- ms-python.debugpy - Python debugger
- charliermarsh.ruff - Linting and formatting (matches project tools)
- keesschollaart.vscode-home-assistant - Home Assistant YAML schemas
- redhat.vscode-yaml - YAML language support
- esbenp.prettier-vscode - YAML/JSON formatting
-
ms-toolsai.jupyter - Notebook support for
notebooks/simulate_cover.ipynb
Or install manually:
code --install-extension ms-python.python
code --install-extension ms-python.vscode-pylance
code --install-extension ms-python.debugpy
code --install-extension charliermarsh.ruffThe workspace includes five pre-configured debug configurations (press F5 or click Run and Debug):
Launches Home Assistant with the debugger attached. This matches the behavior of ./scripts/develop:
- Starts Home Assistant on port 8123
- Enables debug mode and logging
- Sets PYTHONPATH to include
custom_components/ - Allows stepping into Home Assistant core code
Usage:
- Set breakpoints in integration code (e.g.,
coordinator.py:337) - Press F5 and select "Debug Home Assistant"
- Wait for Home Assistant to start at http://localhost:8123
- Trigger coordinator updates (state changes, time passage)
- Breakpoint will be hit, inspect variables in Debug panel
Context-aware debugging of the currently open test file. Fast iteration on specific test modules.
Usage:
- Open a test file (e.g.,
tests/test_calculation.py) - Set breakpoint in test function
- Press F5 and select "Debug Current Test File"
- Test runs with debugger attached
Runs the entire test suite (172 tests) with debugger support.
Usage:
- Press F5 and select "Debug All Tests"
- Set breakpoints in test files or implementation code
- Step through any failing tests
Debug a single test or group of tests by name/pattern using pytest's -k flag.
Usage:
- Press F5 and select "Debug Specific Test"
- Enter test name or pattern when prompted:
-
test_gamma- All tests with "gamma" in name -
vertical- All tests with "vertical" in name -
test_calculation.py::test_gamma_angle- Specific test
-
Quick access to the most frequently debugged tests (129 calculation tests, 91% coverage).
Usage:
- Press F5 and select "Debug calculation.py Tests"
- Set breakpoints in
calculation.pyortest_calculation.py
Click in the gutter (left of line numbers) to set breakpoints. Common breakpoint locations:
Coordinator:
-
coordinator.py:337-_async_update_data()- Main update loop -
coordinator.py:425-async_check_entity_state_change()- State change handler -
coordinator.py:591-_async_move_cover()- Cover control
Calculations:
-
calculation.py:150-AdaptiveVerticalCover.calculate_position()- Vertical blind logic -
calculation.py:250-AdaptiveHorizontalCover.calculate_position()- Awning logic -
calculation.py:350-AdaptiveTiltCover.calculate_position()- Tilt logic -
calculation.py:500-ClimateCoverState.adapt_position()- Climate mode adjustments
Config Flow:
-
config_flow.py:200-async_step_user()- Initial setup -
config_flow.py:450-async_step_options()- Options flow
| Key | Action | Description |
|---|---|---|
| F5 | Continue | Resume execution until next breakpoint |
| F10 | Step Over | Execute current line, don't step into functions |
| F11 | Step Into | Step into function calls |
| Shift+F11 | Step Out | Step out of current function |
| Shift+F5 | Stop | Stop debugging session |
| Cmd+Shift+F5 | Restart | Restart debugging session |
Home Assistant is async-first. When debugging async code:
-
Set
justMyCode: false(already configured) - Allows stepping into Home Assistant core and asyncio -
Use Step Over (F10) - To skip over
awaitinternals - Watch for task cancellation - Tasks can be cancelled during shutdown
-
Check event loop state - In Debug Console:
hass.loop.is_running()
Example debugging session:
# coordinator.py:337
async def _async_update_data(self) -> dict[str, Any]:
"""Update data via library."""
# Set breakpoint here β
_LOGGER.debug("Updating Adaptive Cover data")
# F10 to step through
sun_azimuth = self.hass.states.get(self._sun_azimuth_sensor).state
# F11 to step into calculate_position()
position = await self._cover.calculate_position(...)
# Inspect variables in Debug panel:
# - self._config_entry.options
# - sun_azimuth
# - positionVariables:
- Expand
selfto inspect coordinator state - Expand
self._config_entry.optionsto see configuration - Hover over variables in editor to see values
Watch Expressions: Add expressions to monitor:
-
self._manual_override- Check override state -
self._last_position- Last calculated position -
self.hass.states.get('sun.sun')- Sun entity state
Call Stack:
- See the full async call chain
- Click frames to navigate context
- Useful for understanding event flow
Debug Console: Execute code in current context:
# Check entity states
self.hass.states.get('sun.sun').attributes
# Test calculations
await self._cover.calculate_position(...)
# Inspect coordinator data
self.data- Open Test Explorer (beaker icon in sidebar)
- Wait for test discovery (finds all 172 tests)
- Click play icon to run individual tests or test files
- Click debug icon to debug with breakpoints
- View test results inline (β pass, β fail)
Tests are automatically discovered from tests/ directory:
- Auto-discover on save - Enabled for fast iteration
-
Pattern:
test_*.pyfiles - Framework: pytest with pytest-asyncio
If tests don't appear:
- Open Command Palette (Cmd+Shift+P)
- Run "Python: Discover Tests"
- Check Output β Python Test Log for errors
From Test Explorer:
- Click individual test to run
- Right-click test file β "Run Test" or "Debug Test"
From Editor:
- Hover over test function name
- Click "Run Test" or "Debug Test" CodeLens
From Terminal:
# Single test
python -m pytest tests/test_calculation.py::test_gamma_angle -v
# Test pattern
python -m pytest tests/ -k "gamma" -v
# Test file
python -m pytest tests/test_calculation.py -vAccess tasks via Terminal β Run Task (or Cmd+Shift+P β "Tasks: Run Task"):
| Task | Description | Keyboard Shortcut |
|---|---|---|
| Run Home Assistant on port 8123 | Start development server | - |
| Lint with Ruff | Run linting with click-to-navigate errors | - |
| Run All Tests | Execute full test suite (172 tests) | - |
| Run Tests with Coverage | Generate coverage reports (HTML + terminal) | - |
| Format Code | Auto-format all files with ruff | - |
| Check Pre-commit Hooks | Validate pre-commit configuration | - |
| Setup Development Environment | Run scripts/setup
|
- |
Task Features:
- Problem matchers - Click errors to jump to code
- Instance limits - Prevents multiple Home Assistant instances
- Dedicated panels - Separate terminal for each task
The integrated terminal is pre-configured for development:
Automatic venv activation:
- New terminals automatically activate
venv/ - Prompt shows
(venv)when active
PYTHONPATH configuration:
- Includes
custom_components/directory - Enables imports:
from custom_components.adaptive_cover_pro import coordinator
Verify setup:
# Check venv
which python
# Should output: /Users/jasonrhubottom/Repositories/adaptive-cover/venv/bin/python
# Check PYTHONPATH
echo $PYTHONPATH
# Should include: .../custom_components
# Test import
python -c "from custom_components.adaptive_cover_pro import coordinator"
# Should succeed without errorsThe workspace includes optimized settings for development:
Code Quality:
- Ruff for linting and formatting (matches pre-commit hooks)
- Format on save enabled for Python files
- Auto-fix and organize imports on save
- Inline error highlighting with Error Lens extension
Python Configuration:
- Python 3.11+ from
venv/bin/python - IntelliSense with
custom_components/in analysis path - Basic type checking enabled
Test Configuration:
- Pytest framework with auto-discovery
- Test discovery on save
-
-v --no-covflags for interactive testing (faster)
Performance Optimizations:
- Excludes venv, caches, coverage from search and file watcher
- Limits test discovery to
tests/directory only
Symptoms: Breakpoint shows gray circle, never triggers
Solutions:
-
Check Python interpreter:
- Open Command Palette (Cmd+Shift+P)
- "Python: Select Interpreter"
- Choose
venv/bin/python
-
Verify PYTHONPATH:
- Debug Console:
import sys; print(sys.path) - Should include
.../custom_components
- Debug Console:
-
Check justMyCode setting:
- Verify
"justMyCode": falsein launch.json - Required for stepping into Home Assistant core
- Verify
-
Rebuild caches:
- Delete
__pycache__/directories - Delete
.pytest_cache/ - Restart VS Code
- Delete
Symptoms: ModuleNotFoundError: No module named 'custom_components'
Solutions:
-
Check PYTHONPATH in launch config:
"env": { "PYTHONPATH": "${workspaceFolder}/custom_components" }
-
Verify workspace folder:
- Open Command Palette
- "File: Open Folder"
- Ensure
/Users/jasonrhubottom/Repositories/adaptive-coveris the workspace root
-
Check terminal PYTHONPATH:
echo $PYTHONPATH # Should include custom_components path
Symptoms: Debugger takes forever to start or step through code
Solutions:
-
Disable coverage during debugging:
- Use
--no-covflag (already configured in launch.json)
- Use
-
Enable justMyCode (for faster debugging):
- If you don't need to step into Home Assistant core:
"justMyCode": true
-
Limit test scope:
- Use "Debug Current Test File" instead of "Debug All Tests"
- Use "Debug Specific Test" with
-kpattern
-
Check for infinite loops:
- Review recent code changes
- Check coordinator update logic
Symptoms: Test Explorer shows "No tests discovered"
Solutions:
-
Check Python interpreter:
- Must be
venv/bin/pythonwith pytest installed
- Must be
-
Verify pytest settings:
- Check
.vscode/settings.jsonhaspython.testing.pytestEnabled: true - Check
python.testing.pytestArgsincludes"tests"
- Check
-
Check for syntax errors:
- Open test files and check for linting errors
- Run
python -m pytest tests/ --collect-onlyin terminal
-
Force test discovery:
- Command Palette β "Python: Discover Tests"
- Check Output β Python Test Log
-
Reinstall test dependencies:
source venv/bin/activate pip install -e ".[test]"
Symptoms: No linting errors shown, format on save doesn't work
Solutions:
-
Check Ruff extension installed:
- Extensions β Search "charliermarsh.ruff"
- Install if missing
-
Verify Ruff path:
source venv/bin/activate which ruff # Should output: .../venv/bin/ruff
-
Check settings.json:
"ruff.enable": true, "ruff.path": ["${workspaceFolder}/venv/bin/ruff"]
-
Reload window:
- Command Palette β "Developer: Reload Window"
Set breakpoints that only trigger when a condition is true:
- Right-click breakpoint β "Edit Breakpoint"
- Choose "Expression"
- Enter condition:
# Break only when temperature is low temp < 18 # Break only for specific cover self._config_entry.entry_id == "abc123" # Break only during manual override self._manual_override is True
Log messages without stopping execution:
- Right-click gutter β "Add Logpoint"
- Enter message with expressions in braces:
Position calculated: {position}, Sun azimuth: {sun_azimuth} - Messages appear in Debug Console without pausing
Monitor values that change during execution:
Common watch expressions:
# Coordinator state
self._manual_override
self._last_position
self._last_update
# Cover state
self.hass.states.get('cover.living_room_blind').state
self.hass.states.get('cover.living_room_blind').attributes['current_position']
# Sun state
self.hass.states.get('sun.sun').attributes['azimuth']
self.hass.states.get('sun.sun').attributes['elevation']
# Config options
self._config_entry.options['window_azimuth']
self._config_entry.options['climate_mode_enabled']Break on all exceptions or specific exception types:
- Open Run and Debug view
- Click "Breakpoints" section
- Check "Raised Exceptions" or "Uncaught Exceptions"
- Or right-click β "Add Exception Breakpoint" for specific type
Useful for:
- Catching errors in async code
- Finding silent failures
- Debugging state validation issues
Execute Python code in the current debug context:
# Inspect Home Assistant state
self.hass.states.async_all()
# Check specific entity
state = self.hass.states.get('sun.sun')
print(state.state, state.attributes)
# Test coordinator methods
await self._async_update_data()
# Simulate state change
self.hass.states.async_set('sun.sun', 'above_horizon', {'azimuth': 180})
# Check event listeners
self.hass.bus.async_listeners()| Shortcut | Action |
|---|---|
| F5 | Start debugging / Continue |
| Shift+F5 | Stop debugging |
| Cmd+Shift+F5 | Restart debugging |
| F9 | Toggle breakpoint |
| F10 | Step over |
| F11 | Step into |
| Shift+F11 | Step out |
| Cmd+K Cmd+I | Show hover info |
| Cmd+Shift+P | Command Palette |
| Command | Purpose |
|---|---|
| Python: Select Interpreter | Choose venv Python |
| Python: Discover Tests | Refresh test list |
| Tasks: Run Task | Execute development task |
| Developer: Reload Window | Restart VS Code window |
| Python: Clear Cache | Clear IntelliSense cache |
| Path | Purpose |
|---|---|
.vscode/launch.json |
Debug configurations |
.vscode/settings.json |
Workspace settings |
.vscode/tasks.json |
Development tasks |
.vscode/extensions.json |
Recommended extensions |
venv/bin/python |
Python interpreter |
tests/ |
Test suite (172 tests) |
config/ |
Development HA instance |
π Getting Started
- Installation
- Migrating from Custom Repository
- Migrating from Adaptive Cover
- First-Time Setup
- Cover Types
π§ Core Concepts
π Cover Types
βοΈ Configuration
- Sun Tracking
- Position
- Glare Zones
- Automation
- Custom Position
- Force Override
- Weather Safety
- Climate
- Blindspot
- Summary Screen
- Debug & Diagnostics
π Entities & Services
π¨ Dashboard
π§ Advanced Use Cases
π οΈ Operations
π§ͺ Testing & Simulation
π Reference
π©βπ» For Developers