Skip to content

Fix free electricity session detection by using Go API - #2648

Merged
springfall2008 merged 1 commit into
springfall2008:mainfrom
mgazza:fix-free-electricity-sessions
Sep 13, 2025
Merged

springfall2008 merged 1 commit into
springfall2008:mainfrom
mgazza:fix-free-electricity-sessions

Conversation

@mgazza

@mgazza mgazza commented Sep 9, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

  • Fix free electricity session detection that was failing due to DOM-dependent HTML parsing
  • Check if response is JSON (Go API) or HTML (legacy parsing) based on response type
  • Convert Go API format to PredBat format with proper fallback

Problem

PredBat was failing to detect Octopus Energy free electricity sessions because the existing HTML parsing relied on specific DOM structure that broke when Octopus changed their webpage layout.

Solution

  • Simple response type detection: if JSON, parse as Go API response; if HTML, use legacy parsing
  • The Go API is now publicly available at https://octopus.predbat.com/api/v1/free-sessions
  • Convert Go API JSON response to PredBat's expected format
  • Clean fallback to legacy HTML parsing when needed

Test Plan

  • Verify response type detection works correctly
  • Test JSON format conversion from Go API to PredBat format
  • Confirm fallback to legacy parsing for HTML responses
  • Test with live Octopus free session data

🤖 Generated with Claude Code

- Replace DOM-dependent HTML parsing with Go API integration
- Use dedicated octopus-free-sessions service for reliable parsing
- Add fallback to legacy HTML parsing for backward compatibility
- Improve session data format conversion with proper timezone handling
- This resolves issues where free sessions weren't being detected due to
  changes in Octopus Energy website HTML structure

The Go API uses goquery for better DOM parsing and will be upgraded
to use proper CSS rendering in the future for maximum reliability.
@mgazza
mgazza force-pushed the fix-free-electricity-sessions branch from d37eae2 to 985d0e5 Compare September 9, 2025 12:53
@springfall2008
springfall2008 merged commit 97ec446 into springfall2008:main Sep 13, 2025
1 check passed
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