Repository navigation
Fix for dual day/night rate tariff from octopus, misc bug fixes - #2724
Conversation
Support day/night tariff
There was a problem hiding this comment.
Pull Request Overview
This PR implements support for dual day/night rate tariffs from Octopus Energy and includes several bug fixes for web functionality and logging. The main feature addresses handling of tariffs that have separate day and night rates instead of unified time-based pricing.
- Adds support for Octopus Energy day/night rate tariff handling with automatic detection and rate reconstruction
- Refactors web helper functions to improve code organization and maintainability
- Enhances log filtering functionality with immediate search application for new entries
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/predbat/octopus.py | Implements day/night rate detection and handling for Octopus tariffs |
| apps/predbat/web_helper.py | Extracts CSS and JavaScript functions for better code organization |
| apps/predbat/web.py | Refactors to use extracted helper functions and improves log handling |
| apps/predbat/unit_test.py | Adds test for Octopus URL download functionality and extends rate validation |
| apps/predbat/gecloud.py | Removes debug print statement |
| apps/predbat/fetch.py | Adds safety check for minute data processing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| async def async_get_day_night_rates(self, url): | ||
| """ | ||
| Get day and night rates from Octopus |
There was a problem hiding this comment.
The docstring should describe what the function returns and provide more detail about the day/night rate handling logic.
| Get day and night rates from Octopus | |
| Fetches day and night electricity rates from Octopus Energy and constructs a combined list of rate periods. | |
| The function retrieves the current day and night rates by scanning all available rates and selecting the latest rate valid before the current UTC time. | |
| It then generates a list of rate periods for 8 consecutive days, each with corresponding day and night rates, based on configured start and end times. | |
| Returns: | |
| list of dict: Each dictionary contains 'valid_from', 'valid_to', and 'value_inc_vat' keys representing the start/end time and rate value (including VAT) for each period. |
| url_night = url.replace("standard-unit-rates", "night-unit-rates") | ||
| result_day = await self.fetch_url_cached(url_day) | ||
| result_night = await self.fetch_url_cached(url_night) | ||
| # is_night_rate = self.__is_between_times(rate, "00:30:00", "07:30:00", True) |
There was a problem hiding this comment.
This commented-out code should be removed as it appears to be leftover from development and doesn't serve any purpose in the final implementation.
| # is_night_rate = self.__is_between_times(rate, "00:30:00", "07:30:00", True) |
| detail = data.get("detail", "") | ||
|
|
||
| self.failures_total += 1 | ||
| self.log("Warn: Error downloading Octopus data from URL {} (No Results)".format(url)) |
There was a problem hiding this comment.
The detail variable is retrieved but never used in the error logging. Either use it in the log message or remove the assignment.
| self.log("Warn: Error downloading Octopus data from URL {} (No Results)".format(url)) | |
| self.log("Warn: Error downloading Octopus data from URL {} (No Results) - {}".format(url, detail)) |
| } | ||
| </style> | ||
| """ | ||
| return html |
There was a problem hiding this comment.
Inconsistent spacing - there are extra spaces after 'html'. Should be 'return html' to match Python style conventions.
| return html | |
| return html |
| }}); | ||
| }} | ||
| </script> | ||
| """ |
There was a problem hiding this comment.
Inconsistent spacing - there's an extra space after the triple quotes. Should be '"""' to match the opening quotes.
| """ | |
| """ |
| @@ -379,7 +380,7 @@ def run_nordpool_test(my_predbat): | |||
| if min(fixed.values()) != max(fixed.values()): | |||
| print("ERROR: Fixed rates can not change") | |||
| failed = True | |||
There was a problem hiding this comment.
The magic number change from 5 to 6 days should include a comment explaining why this threshold was increased.
| failed = True | |
| failed = True | |
| # Threshold increased from 5 to 6 days to accommodate new Octopus API data retention policy (June 2024). |
No description provided.