Skip to content

New Feature: Export Price + code style improvements#62

Merged
enoch85 merged 23 commits intomainfrom
feature/export-prices
Jan 30, 2026
Merged

New Feature: Export Price + code style improvements#62
enoch85 merged 23 commits intomainfrom
feature/export-prices

Conversation

@enoch85
Copy link
Copy Markdown
Owner

@enoch85 enoch85 commented Jan 28, 2026

Summary

Adds import price multiplier and export price sensors for prosumers, enabling Belgian-style tariffs and separate feed-in pricing.

Formulas:

  • Import: ((spot × multiplier) + tariff + tax) × (1 + VAT)
  • Export: (spot × multiplier + offset) × (1 + VAT)

Changes

Features

  • Import multiplier (0.0-10.0, default 1.0) for scaling spot prices before fees
  • Six export sensors: Current, Next, Average, Peak, Off-Peak, Tomorrow
  • Export attributes expose interval prices for automations
  • German and Dutch translations

Code Quality

  • Standardized raw_data parameter across all parsers
  • Black formatting (88 chars) applied to codebase
  • Pylint thresholds: production 7.0, tests 5.0
  • Removed dead code and unused imports
  • Python 3.13 support

Bug Fixes

  • Cache invalidation on price-affecting config changes
  • ECB exchange rate caching
  • Parser variable naming and initialization
  • Translation placeholders for hassfest validation

Testing

✅ 427 tests passing (+81 new tests)

Closes #61

Implements Issue #61: Feature for production vs import price difference

This feature allows prosumers who sell electricity back to the grid to track
export/feed-in prices separately from import prices. Export prices are calculated
using the formula: (spot_price × multiplier + offset) × (1 + export_vat)

New configuration options (in Options flow):
- export_enabled: Enable/disable export price sensors
- export_multiplier: Multiplier applied to spot price (e.g., 0.1 for 10%)
- export_offset: Offset added after multiplier (can be negative)
- export_vat: VAT rate for export prices (often 0% for feed-in)

New sensors when export is enabled:
- Export Current Price
- Export Next Interval Price
- Export Average Price
- Export Peak Price
- Export Off-Peak Price
- Tomorrow Export Average Price

Changes:
- const/config.py, defaults.py: Add export config constants
- config_flow/schemas.py: Add export options to schema
- config_flow/options.py: Handle export VAT conversion, cache invalidation
- coordinator/data_models.py: Add export price fields and computed properties
- coordinator/data_processor.py: Calculate export prices from raw spot prices
- sensor/electricity.py: Create export sensors when enabled
- utils/unit_conversion.py: Add convert_export_price function
- translations/en.json, strings.json: Add export option strings

Example usage (Belgium):
- Import: (0.1068 × BELPEX + 1.500) × 1.06
- Export: (0.1 × BELPEX - 1.150) (VAT exempt)

All 346 existing tests pass.
@enoch85 enoch85 changed the title Fix export prices New Feature: Import Price Multiplier Jan 28, 2026
- Shortened comments and split long lines in config.py
- Reformatted defaults.py to fit 88 char limit
- Split long descriptions in schemas.py across multiple lines
- Shortened docstrings and log messages in unit_conversion.py
- Reformatted currency_converter.py docstrings and logs
- All modified files now pass pylint line-length check (10.00/10)

Modified files are clean. Pre-existing issues in other files remain.
- Remove duplicate parse_interval_key function (already imported from data_validity)
- Initialize variables early in DataProcessor.process() to avoid possibly-used-before-assignment
- Fix except clause order in test_15min_migration.py (catch AssertionError before Exception)
- Return None instead of instantiating abstract BasePriceParser (fixes runtime crash)
- Fix non-existent self.now/self.target_timezone in TimezoneConverter (use datetime.now pattern)
- Format code with black

All 346 tests pass.
@enoch85 enoch85 changed the title New Feature: Import Price Multiplier New Feature: Export Price Jan 28, 2026
- Fix E0602 (undefined-variable): data -> raw_data in parsers
- Fix E0110 (abstract-class-instantiated): Raise ValueError for unknown sources
- Fix E0401 (import-error): Remove redundant import in data_fetch.py
- Fix W0237 (arguments-renamed): All parsers use 'raw_data' parameter
- Fix W0221 (arguments-differ): Parser signatures match base class
- Add comprehensive parser parameter tests (61 tests)
- Add .python-version for Python 3.13
- Format with black

All 407 tests passing
@enoch85 enoch85 changed the title New Feature: Export Price New Feature: Export Price + code style improvements Jan 28, 2026

This comment was marked as resolved.

Repository owner deleted a comment from Copilot AI Jan 29, 2026
- Add IMPORT_MULTIPLIER to cache invalidation (fixes stale cache bug)
- Remove unused display_unit_multiplier parameter from _calculate_export_prices
- Remove unused convert_export_price function from unit_conversion
- Add export_attrs to export sensors (exposes interval prices for automations)
- Add comprehensive test coverage (test_import_export_prices.py)
- Remove unused imports from test files
- Fix test mock to return IntervalPriceData

All 427 tests passing.
- Replace direct URLs in translations with {stromligning_docs_url} placeholder
- Add stromligning_docs_url to description_placeholders in config flow
- Fixes hassfest error: URLs must use placeholders, not be embedded directly
- Applied to both strings.json and en.json
- Updated implementation.py and options.py to provide URL value

Resolves: Home Assistant hassfest validation error for translation URLs
@enoch85
Copy link
Copy Markdown
Owner Author

enoch85 commented Jan 29, 2026

I have tested this for a day now (not the export function though).

Generally everything checks out, and if beta6 doesn't include any new bugs I plan to merge tomorrow.

@acejoh Please test beta6 and come back with any findings you might encounter.

Lower pylint failure threshold for test code analysis from 7.0 to 5.0.
@enoch85 enoch85 merged commit 7ff24db into main Jan 30, 2026
14 checks passed
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.

Feature: production vs import difference

2 participants