Skip to content

Document the full API, add periodic charge/discharge endpoints, fix error handling - #28

Open
Poshy163 wants to merge 1 commit into
CharlesGillanders:mainfrom
Poshy163:feat/api-docs-and-timecharge
Open

Document the full API, add periodic charge/discharge endpoints, fix error handling#28
Poshy163 wants to merge 1 commit into
CharlesGillanders:mainfrom
Poshy163:feat/api-docs-and-timecharge

Conversation

@Poshy163

@Poshy163 Poshy163 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Mirrors the AlphaESS developer portal docs into docs/ and adds the two periodic charge/discharge endpoints.

Also contains the fixes from #26 / #27, and bumps the version to 0.0.20.

Docs

The portal needs an account to read, which makes it awkward to point people at. So it's mirrored here:

  • docs/API.md - all 19 endpoints, what each takes and returns, with a real response for each
  • docs/RETURN_CODES.md - the return code table (both pages of it)

I called every endpoint while writing it and hit a few things the portal gets wrong:

  • getVerificationCode is GET, not POST. POST just 405s, so our version could never have worked.
  • bindSn is POST, not GET like the Postman collection in the repo has it
  • getOneDayPowerBySn returns cbat / pchargingPile, the docs say cobat / pChargingPile
  • there's a 6017 No operation permissions that isn't in the return code list at all

New endpoints

getTimeChargeBySn / setTimeChargeBySn. Same idea as updateChargeConfigInfo but you get 6 periods a day instead of 2, per weekday, with a power setpoint.

Wired into getdata() behind get_timecharge=False. It's after self_delay in the signature so existing positional calls don't break.

Not every system can use it. Mine (SMILE5) returns 6017 on both inverters, so that's treated as "not available" rather than an error.

Fixes

…ix error handling

Supersedes the work on feature/time-charge-endpoints, whose RETURN_CODES
table, success-detection helper and tests are carried over here.

Documentation
-------------
The developer portal needs registration to read, so mirror it in docs/:

- docs/API.md - all 19 endpoints, each with what it needs, what it returns
  (every field, type and unit), a captured live response, and the matching
  library method.
- docs/RETURN_CODES.md - the complete return code table (both pages of the
  portal's paginated list), grouped by cause.

Verified endpoint by endpoint against the live API, which turned up four
places where the official documentation is wrong:

- getVerificationCode is GET, not POST (POST returns HTTP 405)
- bindSn is POST, not GET as the bundled Postman collection has it
- getOneDayPowerBySn returns cbat/pchargingPile, not cobat/pChargingPile
- return code 6017 "No operation permissions" exists but is unpublished

New endpoints
-------------
getTimeChargeBySn and setTimeChargeBySn - the periodic (weekly) scheduler.
Up to 6 periods per day, per-weekday selection and a power setpoint per
period, where updateChargeConfigInfo only offers two daily periods.

Exposed on getdata() behind get_timecharge=False. The flag is appended
after self_delay so existing positional callers are unaffected.

Not every system is entitled to it - systems without the feature answer
6017, which is handled as "feature unavailable" rather than an error.

Fixes
-----
- getVerificationCode used POST, which the API rejects with a 405. It could
  never have worked. Now GET.

- Wrapper methods caught exceptions from api_get()/api_post(), logged them
  and returned None without re-raising, so a transport failure reached the
  caller indistinguishable from an empty result. homeassistant-alphaESS
  relies on the exception surfacing to mark an update failed and retry with
  backoff, so entities could sit unavailable long after the network
  recovered. All 19 wrappers now re-raise. Fixes CharlesGillanders#26.

- api_post() logged an error on success-with-payload and returned None
  silently on genuine API errors - the two branches were inverted, so a
  failed write was invisible. Return values are unchanged.

- Success detection now accepts code 200, "msg" or "info". The portal
  documents the periodic endpoints as using "info" while the live API
  returns "msg" for all 19.

- Failed responses now log the decoded return code description, so
  "6017" reads as "(No operation permissions)" instead of a bare number.

Tests
-----
34 tests, no network access - the aiohttp session is mocked. Cover the new
endpoints, success detection via each of the three signals, that transport
errors re-raise from all 19 wrappers, that API-level errors still return
None, that getVerificationCode issues a GET, and that getdata keeps
self_delay positional.
@Poshy163

Poshy163 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

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.

1 participant