-
Notifications
You must be signed in to change notification settings - Fork 12
Default logic: Charge rate optimization #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -156,5 +156,175 @@ def test_discharge_allowed_because_highest_price(self): | |||||
| result = self.logic.get_inverter_control_settings() | ||||||
| self.assertTrue(result.allow_discharge, "Discharge should be allowed") | ||||||
|
|
||||||
| def test_charge_calculation_when_charging_possible(self): | ||||||
| """Test charge calculation when charging is possible due to low SOC""" | ||||||
| stored_energy = 2000 # 2 kWh, well below charging limit (79% = 7.9 kWh) | ||||||
| stored_usable_energy, free_capacity = self._calculate_battery_values( | ||||||
| stored_energy, self.max_capacity | ||||||
| ) | ||||||
|
|
||||||
| # Setup scenario with high future prices to trigger charging | ||||||
| consumption = np.array([1000, 2000, 1500]) # Higher consumption in future hours | ||||||
| production = np.array([0, 0, 0]) # No production | ||||||
|
|
||||||
| calc_input = CalculationInput( | ||||||
| consumption=consumption, | ||||||
| production=production, | ||||||
| prices={0: 0.20, 1: 0.35, 2: 0.30}, # Low current price, high future prices | ||||||
| stored_energy=stored_energy, | ||||||
| stored_usable_energy=stored_usable_energy, | ||||||
| free_capacity=free_capacity, | ||||||
| ) | ||||||
|
|
||||||
| # Test at 30 minutes past the hour to test charge rate calculation | ||||||
| calc_timestamp = datetime.datetime(2025, 6, 20, 12, 30, 0, tzinfo=datetime.timezone.utc) | ||||||
| self.assertTrue(self.logic.calculate(calc_input, calc_timestamp)) | ||||||
| result = self.logic.get_inverter_control_settings() | ||||||
| calc_output = self.logic.get_calculation_output() | ||||||
|
|
||||||
| # Verify charging is enabled | ||||||
| self.assertFalse(result.allow_discharge, "Discharge should not be allowed when charging needed") | ||||||
| self.assertTrue(result.charge_from_grid, "Should charge from grid when energy needed for high price hours") | ||||||
| self.assertGreater(result.charge_rate, 0, "Charge rate should be greater than 0") | ||||||
| self.assertGreater(calc_output.required_recharge_energy, 0, "Should calculate required recharge energy") | ||||||
|
|
||||||
| def test_charge_calculation_when_charging_not_possible_high_soc(self): | ||||||
| """Test charge calculation when charging is not possible due to high SOC""" | ||||||
| # Set SOC above charging limit (79%) | ||||||
| stored_energy = 8000 # 8.0 kWh, above charging limit of 7.9 kWh | ||||||
|
||||||
| stored_energy = 8000 # 8.0 kWh, above charging limit of 7.9 kWh | |
| stored_energy = 8000 # 8.0 kWh, above charging limit of 7.9 kWh |
MaStr marked this conversation as resolved.
Show resolved
Hide resolved
MaStr marked this conversation as resolved.
Show resolved
Hide resolved
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.
Uh oh!
There was an error while loading. Please reload this page.