New Feature: Export Price + code style improvements#62
Merged
Conversation
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.
- 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.
- 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
- 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
Owner
Author
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds import price multiplier and export price sensors for prosumers, enabling Belgian-style tariffs and separate feed-in pricing.
Formulas:
((spot × multiplier) + tariff + tax) × (1 + VAT)(spot × multiplier + offset) × (1 + VAT)Changes
Features
Code Quality
raw_dataparameter across all parsersBug Fixes
Testing
✅ 427 tests passing (+81 new tests)
Closes #61