Guard against getESSList() returning None ('NoneType' object is not iterable)#25
Merged
CharlesGillanders merged 2 commits intoJun 5, 2026
Conversation
When the Alpha ESS API returns a non-success or empty payload (e.g.
{'code': 6026, 'msg': 'network is busy', 'data': None}, or any response
where data is null), api_get() logs it and returns None, so getESSList()
returns None.
getdata() and authenticate() then iterate `units` directly:
units = await self.getESSList()
for idx, unit in enumerate(units): # 'NoneType' object is not iterable
raising "'NoneType' object is not iterable" (logged under the
alphaess.alphaess logger and re-raised) on every affected poll. This is a
transient cloud condition, so guard both call sites to skip the cycle
gracefully instead of throwing.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CharlesGillanders
requested changes
Jun 5, 2026
CharlesGillanders
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR, I'm happy to accept it but could please also edit setup.py to bump the version number?
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Thanks for the quick review! Bumped |
CharlesGillanders
approved these changes
Jun 5, 2026
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.
Problem
getESSList()is declared-> Optional[list]and legitimately returnsNonewhenever the underlyingapi_get()receives a non-success / empty payload or the Alpha ESS cloud is briefly unreachable (connection timeout,Cannot connect to host openapi.alphaess.com).But
getdata()andauthenticate()iterate the result without aNonecheck:So any time
getESSList()returnsNone, the entire poll raises'NoneType' object is not iterable(logged under thealphaess.alphaesslogger and re-raised). Observed in the wild on a transient cloud hiccup:(The Home Assistant integration catches it downstream and falls back, but the library shouldn't throw on a return value its own type hint declares possible.)
Fix
Guard both iteration sites against
None:getdata()logs a warning and returns the (empty)alldatalist, so the caller keeps its previous data instead of crashing.authenticate()returnsFalse.No behavioural change when the API responds normally.