Skip to content

Read the resource tree only once and cache it - #22

Draft
Xitee1 wants to merge 2 commits into
StephanU:mainfrom
Xitee1:read-resources-only-once
Draft

Read the resource tree only once and cache it#22
Xitee1 wants to merge 2 commits into
StephanU:mainfrom
Xitee1:read-resources-only-once

Conversation

@Xitee1

@Xitee1 Xitee1 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What

DataProvider.read_data() fetched both /api/v1/var (the full resource tree) and /api/v1/var/status on every call. The resource tree is the largest response the Query API produces and only changes when the myGEKKO configuration itself is changed, so this PR fetches it only on the first read_data() call and caches it afterwards. Every subsequent cycle only requests /api/v1/var/status.

Why

  • Halves the number of requests per polling cycle — relevant for the Plus Query API, which enforces rate/burst limits (HTTP 429).
  • Avoids repeatedly transferring the biggest payload, which is especially noticeable with the 30s polling interval of the Home Assistant integration.

Notes

  • If the initial resources fetch fails (or its JSON is invalid), resources stays None and the next read_data() call retries it, matching the previous behavior.
  • A config change on the controller (e.g. renaming/adding items) is picked up again after re-creating the client — same as the Home Assistant integration behaves today, where entities are only created at setup anyway.
  • Added a test asserting /api/v1/var is requested once across two read_data() calls while /api/v1/var/status is requested each time.

🤖 Generated with Claude Code

The /api/v1/var resource tree only changes when the myGEKKO
configuration is changed, but it was fetched on every read_data()
call together with /api/v1/var/status. Fetching it once and caching
it halves the number of requests per polling cycle and avoids
transferring the largest API response over and over.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Xitee1
Xitee1 marked this pull request as draft July 15, 2026 07:15
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