Skip to content

Fix for dual day/night rate tariff from octopus, misc bug fixes - #2724

Merged
springfall2008 merged 6 commits into
mainfrom
fixes3
Oct 5, 2025
Merged

springfall2008 merged 6 commits into
mainfrom
fixes3

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

No description provided.

@springfall2008 springfall2008 changed the title Fix for dual day/night rate tariff from octopus Fix for dual day/night rate tariff from octopus, misc bug fixes Oct 5, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/predbat/octopus.py

async def async_get_day_night_rates(self, url):
"""
Get day and night rates from Octopus

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring should describe what the function returns and provide more detail about the day/night rate handling logic.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/octopus.py
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)

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# is_night_rate = self.__is_between_times(rate, "00:30:00", "07:30:00", True)

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/octopus.py
detail = data.get("detail", "")

self.failures_total += 1
self.log("Warn: Error downloading Octopus data from URL {} (No Results)".format(url))

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detail variable is retrieved but never used in the error logging. Either use it in the log message or remove the assignment.

Suggested change
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))

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/web_helper.py Outdated
}
</style>
"""
return html

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing - there are extra spaces after 'html'. Should be 'return html' to match Python style conventions.

Suggested change
return html
return html

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/web_helper.py Outdated
}});
}}
</script>
"""

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing - there's an extra space after the triple quotes. Should be '"""' to match the opening quotes.

Suggested change
"""
"""

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/unit_test.py
@@ -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

Copilot AI Oct 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number change from 5 to 6 days should include a comment explaining why this threshold was increased.

Suggested change
failed = True
failed = True
# Threshold increased from 5 to 6 days to accommodate new Octopus API data retention policy (June 2024).

Copilot uses AI. Check for mistakes.
@springfall2008
springfall2008 merged commit 2d862f8 into main Oct 5, 2025
1 check passed
@springfall2008
springfall2008 deleted the fixes3 branch October 5, 2025 10:39
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.

2 participants