Skip to content

Kostal Piko: cache http readings - #36659

Merged
andig merged 4 commits into
masterfrom
fix/issue-36658
Nov 27, 2026
Merged

andig merged 4 commits into
masterfrom
fix/issue-36658

Conversation

@andig

@andig andig commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

fixes #36658

The Kostal Piko templates read each value from its own dxs.json?dxsEntries=... URL, and no URL is used twice in a template. The warning fires because the same full URL is fetched twice within a second, and the inverter sends no cache headers. Every http source in kostal-piko-pv (Piko, Piko BA) and kostal-piko-hybrid now caches its reading, configurable through a new cache param with default 1s. Query parameters stay part of the cache key, so different readings never share a cached response.

🤖 Generated with Claude Code

@andig andig added the devices Specific device support label Nov 27, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 822c018

#36658 uncached request repeated within 1s warnings with Kostal Piko BA (multiple meters on same dxs.json endpoint) · 1 of 1 met

# Requirement Status Notes
1 Prevent repeated uncached-request warnings for the Kostal Piko BA meters sharing the inverter host. ✅ Met The Piko PV template and the hybrid battery template add a configurable 1s cache to their HTTP readings, including the URLs shown in the issue’s warnings.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="plugin/http.go" line_range="271" />
<code_context>
 // the response should be cached. It fires once per url to avoid log spam.
 func repeatedGet(url string, now time.Time) bool {
+	// a query selects the values to read, such requests are not expected to be cached
+	if strings.Contains(url, "?") {
+		return false
+	}
</code_context>
<issue_to_address>
**Uncached query polling goes unnoticed**

When a repeated uncached GET uses query parameters for metadata or another purpose rather than selecting values to read, `repeatedGet` returns false for every URL containing `?`, so the request path never logs its uncached-repeat warning and operators miss polling that may need caching.

Limit the exemption to query forms known to select values, or preserve repeat warnings for other query URLs.
</issue_to_address>

### Comment 2
<location path="plugin/http.go" line_range="271" />
<code_context>
 // the response should be cached. It fires once per url to avoid log spam.
 func repeatedGet(url string, now time.Time) bool {
+	// a query selects the values to read, such requests are not expected to be cached
+	if strings.Contains(url, "?") {
+		return false
+	}
</code_context>
<issue_to_address>
**Fragment question marks suppress warnings**

When a configured URI has no query but its fragment contains `?`, `repeatedGet` mistakes the fragment’s `?` for a query and skips tracking the URL, even though HTTP omits fragments from requests; repeated uncached GETs therefore produce no warning.

Parse the URL and check its query component instead of searching the raw URL for `?`.
</issue_to_address>

### Comment 3
<location path="plugin/http_test.go" line_range="232-234" />
<code_context>
-	require.False(t, repeatedGet("http://q.test/path?ts=1", t0))
-	require.False(t, repeatedGet("http://q.test/path?ts=2", t0.Add(300*time.Millisecond)))
+	// urls with query params are exempt, even when repeated
+	query := "http://q.test/api/dxs.json?dxsEntries=33556229"
+	require.False(t, repeatedGet(query, t0))
+	require.False(t, repeatedGet(query, t0.Add(300*time.Millisecond)))
 }
</code_context>
<issue_to_address>
**New test case stays positional**

When a new request scenario is added to this multi-case test, the added query-URL scenario uses positional assertions in `TestRepeatedGet` instead of a struct-driven table, so the expanded multi-case test does not follow the repository's required test pattern.

Represent the scenarios as cases in a struct-driven table and run them as table subtests.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread plugin/http.go Resolved
Comment thread plugin/http.go Resolved
Comment thread plugin/http_test.go Resolved
@andig andig changed the title HTTP plugin: no uncached warning for requests with query params Kostal Piko: cache http readings for 1s Nov 27, 2026
@andig andig changed the title Kostal Piko: cache http readings for 1s Kostal Piko: cache http readings Nov 27, 2026
@andig
andig enabled auto-merge (squash) November 27, 2026 16:58
@andig
andig merged commit f74f3d5 into master Nov 27, 2026
14 checks passed
@andig
andig deleted the fix/issue-36658 branch November 27, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devices Specific device support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uncached request repeated within 1s warnings with Kostal Piko BA (multiple meters on same dxs.json endpoint)

1 participant