Skip to content

Dynamic load feature - #2702

Merged
springfall2008 merged 6 commits into
mainfrom
fixes6
Sep 28, 2025
Merged

springfall2008 merged 6 commits into
mainfrom
fixes6

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

No description provided.

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 a dynamic load feature that adjusts load predictions based on real-time consumption patterns. The feature analyzes recent load data to classify periods as "high", "low", or "baseline" and makes corresponding adjustments to predictions and car charging schedules.

  • Adds dynamic load analysis functionality with real-time load classification
  • Implements load baseline adjustments and car charging slot modifications
  • Updates sensor outputs and dashboard items for better monitoring

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/predbat/predbat.py Version bump and initialization of dynamic load variables
apps/predbat/plan.py Core dynamic load logic implementation and sensor updates
apps/predbat/gecloud.py Load period calculation and API pagination increase
apps/predbat/fetch.py Configuration option and load baseline application
apps/predbat/energydataservice.py Cleanup of debug print statements
apps/predbat/config.py New configuration options for dynamic load features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread apps/predbat/plan.py

# Last period load analysis
self.load_last_status = "baseline"
if self.load_last_period > self.battery_rate_max_discharge * MINUTE_WATT / 1000:

Copilot AI Sep 28, 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 1000 appears to be a unit conversion factor. Consider defining it as a named constant (e.g., WATTS_TO_KW = 1000) to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/plan.py
Comment on lines +39 to +45
def dynamic_load(self):

# Last period load analysis
self.load_last_status = "baseline"
if self.load_last_period > self.battery_rate_max_discharge * MINUTE_WATT / 1000:
self.load_last_status = "high"
elif (self.load_last_period < self.battery_rate_max_discharge * 0.9 * MINUTE_WATT / 1000) and (self.load_last_period < self.car_charging_threshold * 0.9):

Copilot AI Sep 28, 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 0.9 appears twice in this condition. Consider defining it as a named constant (e.g., LOW_LOAD_FACTOR = 0.9) to improve maintainability and make the threshold configurable.

Suggested change
def dynamic_load(self):
# Last period load analysis
self.load_last_status = "baseline"
if self.load_last_period > self.battery_rate_max_discharge * MINUTE_WATT / 1000:
self.load_last_status = "high"
elif (self.load_last_period < self.battery_rate_max_discharge * 0.9 * MINUTE_WATT / 1000) and (self.load_last_period < self.car_charging_threshold * 0.9):
LOW_LOAD_FACTOR = 0.9
def dynamic_load(self):
# Last period load analysis
self.load_last_status = "baseline"
if self.load_last_period > self.battery_rate_max_discharge * MINUTE_WATT / 1000:
self.load_last_status = "high"
elif (self.load_last_period < self.battery_rate_max_discharge * self.LOW_LOAD_FACTOR * MINUTE_WATT / 1000) and (self.load_last_period < self.car_charging_threshold * self.LOW_LOAD_FACTOR):

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/plan.py
self.dynamic_load_baseline = {}
if self.metric_dynamic_load_adjust:
minutes_now = self.minutes_now
minutes_end_slot = int((self.minutes_now + 30) / 30) * 30

Copilot AI Sep 28, 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 30 (representing a 30-minute period) appears multiple times. Consider defining it as a named constant (e.g., SLOT_DURATION_MINUTES = 30) to improve maintainability.

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/gecloud.py
Comment on lines +1336 to +1338
url += "&pageSize=8000"
else:
url += "?pageSize=4096"
url += "?pageSize=8000"

Copilot AI Sep 28, 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 8000 for page size should be defined as a named constant (e.g., GE_API_PAGE_SIZE = 8000) to improve maintainability and make it easier to adjust if needed.

Copilot uses AI. Check for mistakes.
@springfall2008
springfall2008 merged commit 1ae66a6 into main Sep 28, 2025
1 check passed
@springfall2008
springfall2008 deleted the fixes6 branch September 28, 2025 17:48
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