Repository navigation
feat(drivers): add host.http_put for device APIs that write with PUT - #2028
Open
yogiohlsson-ai wants to merge 1 commit into
Open
yogiohlsson-ai wants to merge 1 commit into
yogiohlsson-ai wants to merge 1 commit into
Conversation
sonnenBatterie's JSON API v2 changes its operating mode only through PUT /api/v2/configurations; PATCH and POST there return 404. Add host.http_put, sharing http_patch's implementation and gates: capabilities.http plus allow_write, allowed_hosts, no writes during a fingerprint probe, a JSON default Content-Type the driver can override. The redirect policy now refuses a redirected PUT as it does PATCH, so a 301/302/303 cannot turn the write into a body-less GET that reports success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jörgen Ohlsson <yogiohlsson@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Need
A sonnenBatterie can only be steered through its local JSON API v2 by
switching its operating mode, and the unit accepts that write only as
PUT /api/v2/configurations. The Lua host offershttp_patchandhttp_postfor plain-HTTP writes;http_requestallows only GET and POSTover https. A sonnen control driver therefore cannot be written today.
Measured on one sonnenBatterie (software 1.40.5, JSON API v2, port 80) on
2026-11-13, with the unit's Auth-Token. The first row put the unit in manual
mode and the second set it back from 1 to 2. Every row except the first two
was sent with
EM_OperatingMode2, the mode the unit was already in, so itchanged nothing:
/api/v2/configurationsPUTEM_OperatingMode=1{"EM_OperatingMode":"1"}; mode read back as 1PUTEM_OperatingMode=2{"EM_OperatingMode":"2"}; mode read back as 2PUT{"EM_OperatingMode":"2"}{"EM_OperatingMode":"2"}POSTEM_OperatingMode=2POST{"EM_OperatingMode":"2"}PATCHEM_OperatingMode=2PATCH with a JSON body was not tried. The owner repeated the PATCH and POST
requests on the unit and got 404 for both.
The controllable sonnen driver itself belongs in srcfl/device-drivers and
will follow as a separate PR once this host function exists. This PR changes
no driver.
Change
host.http_put(url, body, headers?)shares one implementation withhost.http_patch: samecapabilities.httpandcapabilities.http.allow_writegates,allowed_hostsfence, read-onlyprobe and runtime-policy refusal (
allowWrite("http.put")), JSON defaultContent-Type that a driver header overrides, 1 MB response cap and
HTTP <status>error for 4xx/5xx.PUTas italready did for
PATCH. Without this, Go re-issues a 301/302/303 as abody-less GET and the write would report success although it never
reached the device. The new redirect test failed before this line changed.
HTTPAllowWrite/AllowWriteanddocs/writing-a-driver.mdname both verbs.patch(new host function; no existing driver changesbehaviour). The owner may prefer
minor, ashttp_patchused.Tests
New
go/internal/drivers/lua_http_put_test.go:Content-Type(form body) wins over the default;allow_write, without thehttpcapability, outsideallowed_hosts, on redirect and during a fingerprint probe — in everycase the server is never reached (or the redirect target never is).
lua_http_patch_test.goonly gains a verb parameter in its helper; theexisting PATCH tests are unchanged and pass.
Run on a Raspberry Pi 4 Model B Rev 1.5 (aarch64, Debian 13 trixie), with
go version go1.26.0 linux/arm64:
make verifywas not run on the Pi (it needsjq, not installed); thedrivers package ran with the pinned bundled drivers fetched by hand at
1e4b5de7.Overlap
Open #2017 (
fix(battery): explain calibration and suspend manual control)also edits
go/internal/drivers/lua.goanddocs/writing-a-driver.md.Checked on 2026-11-16 with
gh pr view 2017 -R srcfl/ftw: open, not adraft, no reviews, mergeable, head
5cf68a0f65. Its hunks are elsewhere(
set_calibrating).git merge-treeof this branch with that head mergedwithout conflicts. This branch is based on current
master(5b25abcb).🤖 Generated with Claude Code