Skip to content

fix(enphase): delete schedules via POST /<id>/delete, not the DELETE verb - #4429

Merged
springfall2008 merged 2 commits into
mainfrom
enphase-delete-endpoint
Aug 3, 2026
Merged

fix(enphase): delete schedules via POST /<id>/delete, not the DELETE verb#4429
springfall2008 merged 2 commits into
mainfrom
enphase-delete-endpoint

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Follow-up to #4428, which shipped the schedule-conflict fix but used the wrong delete endpoint.

Problem

The schedule cleanup in #4428 issued DELETE /battery/sites/<site>/schedules/<id>. The BatteryConfig gateway does not allow that verb on the resource and rejects it:

DELETE /service/batteryConfig/api/v1/battery/sites/5667604/schedules/9440ae1e-... -> 403 Invalid CORS request

The API exposes deletion as POST /schedules/<id>/delete — as the integration design notes in docs/superpowers/specs/2026-07-11-enphase-cloud-integration-design.md already recorded. The headers were never the problem: Origin/Referer are set for the battery_config family, and GET/PUT on the same base path succeed in the same session with the same headers. Only the verb differed.

In a 15-minute deployed log: 28 delete attempts, all 403, zero successes.

Two consequences:

  • A window Predbat wanted to retire was never cleared, so the disable path retried it on every cycle and never converged.
  • A 403 counts as an auth failure in request_json, so each failed delete also burned a re-login — six Enphase logins in fifteen minutes, against an account that rejects excess sessions. (LOGIN_REUSE_SECONDS = 30 bounded it, and no rejection or suspension was reached, but the churn is unnecessary.)

What #4428 did fix

Same log, same site: zero CONFLICTING_SCHEDULE_* errors, down from 272 in 13 hours. The id-pinning and conflict-retry changes are working; only the delete verb was wrong.

Changes

  • _delete_schedule now POSTs to the /delete sub-resource.
  • Tests updated to assert the exact method and path, plus a new focused test (test_delete_schedule_posts_to_the_delete_endpoint) that pins the endpoint so this cannot regress silently.

Written test-first; the new test failed against the DELETE-verb implementation before the fix. ./run_pre_commit passes — all hooks green, full quick suite green.

Version bumped v8.47.4 → v8.47.5.

🤖 Generated with Claude Code

springfall2008 and others added 2 commits August 3, 2026 14:32
…verb

The schedule cleanup added in the previous commit used DELETE
/battery/sites/<site>/schedules/<id>, which the BatteryConfig gateway
rejects with "403 Invalid CORS request" - the verb is not allowed on that
resource. The API exposes deletion as POST /schedules/<id>/delete, as the
integration design notes already recorded.

Every attempt failed, so a window Predbat wanted to retire was retried on
each cycle and never cleared. A 403 also counts as an auth failure, so
each one burned a re-login: six Enphase logins in fifteen minutes in the
captured log, against an account that rejects excess sessions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 3, 2026 12:33

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 fixes Enphase schedule cleanup by switching schedule deletion from the unsupported DELETE /.../schedules/<id> to the API-supported POST /.../schedules/<id>/delete, preventing persistent 403s and the resulting re-login churn in the Enphase BatteryConfig gateway path.

Changes:

  • Update EnphaseAPI._delete_schedule() to POST to the /delete sub-resource (with allow_empty=True to accept 204/no-body success).
  • Update and extend Enphase API tests to assert the correct delete endpoint/method and prevent regression.
  • Bump Predbat version v8.47.4v8.47.5.

Reviewed changes

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

File Description
apps/predbat/enphase.py Switch schedule deletion to POST .../schedules/<id>/delete and document why (gateway rejects DELETE).
apps/predbat/tests/test_enphase_api.py Add a focused regression test for the POST delete endpoint; update existing tests to match the new delete behavior.
apps/predbat/predbat.py Version bump to v8.47.5.

@springfall2008
springfall2008 merged commit b6282b6 into main Aug 3, 2026
3 checks passed
@springfall2008
springfall2008 deleted the enphase-delete-endpoint branch August 3, 2026 13:25
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