charging price calculation: energy * price for equal prices#3688
Open
LKuemmel wants to merge 2 commits into
Open
charging price calculation: energy * price for equal prices#3688LKuemmel wants to merge 2 commits into
LKuemmel wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts how charging costs are calculated when all configured energy-source prices are identical and electricity pricing is not configured (Ticket #66000952), aiming to simplify the calculation to “energy * price” in that scenario.
Changes:
- Added a dedicated “one-price” calculation path for the equal-prices scenario in
calc_energy_costs. - Refactored the existing cost calculation into
_calc_energy_costs_source_price. - Updated/extended unit tests to cover the new branching behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/control/chargelog/chargelog.py | Adds equal-price shortcut path and splits cost calculation into one-price vs. source-price helpers. |
| packages/control/chargelog/chargelog_test.py | Updates tests for refactor and adds new tests for one-price path and branch coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+327
to
+334
| def calc_energy_costs(cp, create_log_entry: bool = False): | ||
| prices = data.data.general_data.data.prices | ||
| if (prices.bat == prices.cp == prices.grid == prices.pv and | ||
| data.data.optional_data.data.electricity_pricing.configured is False): | ||
| if create_log_entry: | ||
| _calc_energy_costs_one_price(cp) | ||
| else: | ||
| _calc_energy_costs_source_price(cp, create_log_entry) |
Comment on lines
+155
to
+160
| def test_calc_energy_costs_one_price(mock_data): | ||
| cp = Chargepoint(4, None) | ||
| cp.data.set.log.imported_since_mode_switch = 3950 | ||
| prices = data.data.general_data.data.prices | ||
| prices.bat = 0.3 | ||
|
|
Comment on lines
+161
to
+163
| _calc_energy_costs_one_price(cp) | ||
|
|
||
| assert cp.data.set.log.costs == 1185 |
Comment on lines
+169
to
+171
| (True, False, True, 1, 0), | ||
| (True, False, False, 0, 0), | ||
| (True, True, True, 0, 1), |
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.
Ticket #66000952
Gleiche Preise
Unterschiedliche Preise
Dyn. Strompreis