Skip to content

feat: Simulation/paper-trading mode (Issue #21) - #27

Merged
Tsopic merged 8 commits into
mainfrom
feature/simulation-mode
Jan 27, 2026
Merged

feat: Simulation/paper-trading mode (Issue #21)#27
Tsopic merged 8 commits into
mainfrom
feature/simulation-mode

Conversation

@Tsopic

@Tsopic Tsopic commented Jan 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds TradingSimulator class for paper-trading without controlling the inverter
  • Tracks simulated actions (discharge, charge, idle) with timestamps, prices, and reasoning
  • Accumulates revenue, cost, and net profit statistics
  • Supports data export to JSON and CSV formats

Changes

  • New module: simulation.py - Complete simulation engine with dataclasses
    • SimulatedAction - Individual action record
    • SimulationStats - Accumulated statistics with net profit calculation
    • SimulationState - Complete state management
    • TradingSimulator - Main simulator class
  • New tests: test_simulation.py - 25 comprehensive tests
  • Updated: const.py - New constants for simulation entities and services

Key Features

  • simulate_discharge() / simulate_charge() / simulate_idle() - Record what actions would be taken
  • get_recent_actions(limit) - Get recent action log (most recent first)
  • get_stats() - Get accumulated statistics
  • export_to_json() / export_actions_to_csv() - Export for external analysis
  • Maximum 1000 actions in log with FIFO eviction

Test plan

  • All 25 new tests pass
  • Full test suite passes (283 tests)
  • Code formatted with ruff
  • Realistic scenarios tested (typical day, negative prices)
  • Integration with Home Assistant entities (future PR)

Closes #21

🤖 Generated with Claude Code

Tsopic and others added 7 commits December 2, 2025 11:15
- Add comprehensive AI design document for smart battery management
- Document Nord Pool 24h prices as PRIMARY decision driver
- Include solar prediction, load forecasting, and Q-learning optimization
- Design for Raspberry Pi 4 (4GB RAM) constraints
- Add .worktrees/ to .gitignore for git worktree support
- Update CLAUDE.md and README.md with v0.15.0 documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add TradingSimulator class for paper-trading without controlling inverter:
- Track simulated discharge/charge/idle actions with timestamps
- Accumulate simulated revenue, cost, and net profit
- Log actions with energy amounts and reasons
- Export data to JSON or CSV format
- Maximum log size of 1000 actions with FIFO eviction

Components:
- simulation.py: TradingSimulator, SimulatedAction, SimulationStats, SimulationState
- test_simulation.py: 25 comprehensive tests including realistic scenarios
- const.py: New constants for simulation mode entities and services

Benefits:
- Safe testing before live deployment
- Strategy comparison through simulated revenue tracking
- Debug aid with detailed action logging
- Export capability for external analysis

Closes #21

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Incorporates AI features from main branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add scikit-learn, xgboost, onnxruntime to requirements_test.txt
- Add recorder to manifest.json dependencies (used by ai/data_extractor.py)

These fixes resolve CI failures:
- ModuleNotFoundError: No module named 'sklearn'
- Hassfest: Using component recorder but it's not in 'dependencies'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The pytest-cov configuration in pyproject.toml was still set to 90%.
Updating to match the workflow file threshold.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Jan 27, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 99.14530% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...om_components/battery_energy_trading/simulation.py 99.09% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Flag Coverage Δ
unittests 86.06% <99.14%> (+0.53%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
custom_components/battery_energy_trading/const.py 100.00% <100.00%> (ø)
...om_components/battery_energy_trading/simulation.py 99.09% <99.09%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Resolved const.py merge conflict by combining:
- Simulation mode constants (SWITCH_SIMULATION_MODE, simulated sensors, services)
- Dynamic threshold constants from PR #26
- Inverter control types from PR #24

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Tsopic
Tsopic merged commit 7f1f041 into main Jan 27, 2026
8 checks passed
Tsopic added a commit that referenced this pull request Jan 27, 2026
Resolved const.py merge conflict by combining:
- Solar forecast constants (SWITCH_SOLAR_AWARE_MODE, forecast sensors, settings)
- Dynamic threshold constants from PR #26
- Simulation mode constants from PR #27
- Inverter control types from PR #24

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tsopic added a commit that referenced this pull request Jan 27, 2026
Resolved const.py merge conflict by combining:
- Performance tracking constants (SWITCH_ENABLE_PERFORMANCE_TRACKING, profit sensors, services)
- Dynamic threshold constants from PR #26
- Simulation mode constants from PR #27
- Solar forecast constants from PR #28
- Inverter control types from PR #24

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add simulation/paper-trading mode

2 participants