Skip to content

Charge spanning midnight error, more tests, extend token for MCP - #2852

Merged
springfall2008 merged 10 commits into
mainfrom
fixes3
Nov 2, 2025
Merged

springfall2008 merged 10 commits into
mainfrom
fixes3

Conversation

@springfall2008

@springfall2008 springfall2008 commented Nov 2, 2025 •

Copy link
Copy Markdown
Owner

@springfall2008 springfall2008 changed the title Fixes3 Charge spanning midnight error, more tests, extend token for MCP Nov 2, 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 updates Predbat to version 8.27.2, addressing issues with inverter control logic for charge/discharge window management and testing improvements.

  • Fixed button press logic to be more structured and conditional
  • Enhanced charge window handling across midnight boundaries
  • Extended access token lifetime from 1 hour to 24 hours for MCP OAuth
  • Added comprehensive test coverage for midnight-spanning charge scenarios

Reviewed Changes

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

File Description
apps/predbat/predbat.py Version bump to v8.27.2
apps/predbat/web_mcp.py Extended OAuth access token lifetime from 1 to 24 hours
apps/predbat/inverter.py Refactored button press logic and charge schedule enable normalization for better code structure
apps/predbat/unit_test.py Added test parameter for inverter_charge_time_minutes_end, additional logging, new test pages, and comprehensive midnight charge window test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/predbat/unit_test.py
Comment thread apps/predbat/unit_test.py

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/predbat/unit_test.py
print("Test: {}".format(test_name))

inv.rest_data = None
inv.has_inverter_time_button_press = has_inverter_time_button_press

Copilot AI Nov 2, 2025

Copy link

Choose a reason for hiding this comment

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

The variable name has_inverter_time_button_press should be inv_time_button_press to match the actual inverter attribute name used in inverter.py (line 209, 1989, 2059, 2415). This incorrect attribute name will cause the test to fail to set the intended inverter property.

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/unit_test.py
inv.rest_data["Timeslots"]["Charge_start_time_slot_1"] = prev_charge_start_time
inv.rest_data["Timeslots"]["Charge_end_time_slot_1"] = prev_charge_end_time
inv.rest_data["Control"] = {}
inv.rest_data["Control"]["Enable_Charge_Schedule"] = "enable" if prev_enable_charge else "disabled"

Copilot AI Nov 2, 2025

Copy link

Choose a reason for hiding this comment

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

Inconsistent string values: uses 'enable' when true but 'disabled' when false (should be 'disable' to match line 570 and 638). This inconsistency could cause test failures or mask bugs in the actual code.

Suggested change
inv.rest_data["Control"]["Enable_Charge_Schedule"] = "enable" if prev_enable_charge else "disabled"
inv.rest_data["Control"]["Enable_Charge_Schedule"] = "enable" if prev_enable_charge else "disable"

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/inverter.py
Comment on lines +2317 to +2318
if old_charge_schedule_enable in ["off", "disable"]:
old_charge_schedule_enable = "off"

Copilot AI Nov 2, 2025

Copy link

Choose a reason for hiding this comment

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

The normalization only handles 'off' and 'disable' but doesn't handle other possible values like 'enable' or 'on'. Consider adding an else clause to normalize 'enable'/'on' to a consistent 'on' value, or documenting the expected values to ensure robust handling across different states.

Suggested change
if old_charge_schedule_enable in ["off", "disable"]:
old_charge_schedule_enable = "off"
if str(old_charge_schedule_enable).lower() in ["off", "disable"]:
old_charge_schedule_enable = "off"
elif str(old_charge_schedule_enable).lower() in ["on", "enable"]:
old_charge_schedule_enable = "on"

Copilot uses AI. Check for mistakes.
@springfall2008
springfall2008 merged commit 77442e3 into main Nov 2, 2025
7 checks passed
@springfall2008
springfall2008 deleted the fixes3 branch November 2, 2025 18:20
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