Add opt-in AlphaESSApiError so callers can detect API failures - #29
Merged
CharlesGillanders merged 3 commits intoAug 13, 2026
Merged
Conversation
The write endpoints answer with data: null whether they succeed or fail, and
api_post returns json_response["data"] on success and None on failure, so a
successful write is indistinguishable from a rejected one. That left callers
guessing, which is how homeassistant-alphaESS ended up gating a write on an
unrelated read.
Add raise_on_error, defaulting to False. Left alone nothing changes: API-level
failures still log and return None. Set it and they raise AlphaESSApiError
carrying code, msg, expMsg, description and path, so success becomes "did not
raise" rather than a return value nobody can interpret.
Kept backwards compatible on purpose, since people upgrade without reading
changelogs:
- no return type or value changes anywhere
- raise_on_error is appended last in __init__, so positional callers are fine
- transport exceptions propagate exactly as before
- the existing 34 tests pass untouched, and homeassistant-alphaESS's 342
tests pass against this build without opting in
Also verified against the live API and corrected in the docs:
- an empty period list is rejected with 6001 "time list is null"; the docs
previously claimed [] was acceptable. Omitting one gives 10001, a code
outside the 6xxx range and absent from the portal's table.
- parameter validation runs before the entitlement check, so an early 6001
is not evidence that the account has permission
- expMsg is often the only field naming the bad parameter, and was neither
logged nor exposed
- the portal registry holds 21 interfaces, not 19: getMeterOffsetConfigInfo
and updateMeterOffsetConfigInfo are scoped to the commercial & industrial
document and are not callable from a standard account
- getMeterOffsetConfigInfo is GET; the portal documents it as POST, which 405s
The "already logged by __handle_failure" note was on all 25 passthroughs and said the same thing every time, which is noise once you've read it once. Also reworded the new doc sections so they read like someone explaining what they found rather than a spec, and cut the paragraph restating what the table above it already said.
getdata is documented as returning whatever it managed to gather, but with the flag set the first endpoint the account can't use would raise and take the whole poll with it. getTimeChargeBySn answers 6017 on most systems, so that was not a corner case. Each call inside getdata now goes through _best_effort, which leaves that one key None on a refusal. Transport errors still stop it, since those affect every endpoint anyway.
Poshy163
marked this pull request as ready for review
August 13, 2026 06:55
Contributor
Author
|
@CharlesGillanders bump, also needs a release so CharlesGillanders/homeassistant-alphaESS#270 can be finished off |
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.
The write endpoints answer with
data: nullwhether they succeed or fail, andapi_postreturnsjson_response["data"]on success andNoneon failure. So a successful write looks identical toa rejected one and callers are left guessing.
This adds
raise_on_error, off by default. Leave it alone and nothing changes: API-level failureslog and return
Noneas always. Turn it on and they raiseAlphaESSApiErrorwithcode,msg,expMsg,descriptionandpathattached, so success becomes "nothing was raised" instead of areturn value nobody can interpret.
Backwards compatibility
raise_on_errorgoes last in__init__, so positional callers are unaffectedwithout opting in
getdata()stays best-effort with the flag on — a refused endpoint leaves that keyNoneratherthan costing the whole poll, since
getTimeChargeBySnanswers6017on most systems.Bumped to 0.0.21.
Doc corrections, checked against the live API
6001 "time list is null"— Document the full API, add periodic charge/discharge endpoints, fix error handling #28 said[]was fine,which was wrong. Omitting a list gives
10001, outside the6xxxrange and not in the portal'stable.
6001doesn't mean your account hasaccess — you just never got far enough to find out.
expMsgis often the only field naming the bad parameter, and was neither logged nor exposed.getMeterOffsetConfigInfoandupdateMeterOffsetConfigInfoare scoped to the commercial & industrial document, so a standardaccount can't reach them. Documented, not implemented. The portal lists the getter as POST; it's
GET, and POST returns
405.