Skip to content

Add async support using separate files (non-breaking)#151

Draft
johanzander wants to merge 2 commits into
indykoning:masterfrom
johanzander:async-separate-files
Draft

Add async support using separate files (non-breaking)#151
johanzander wants to merge 2 commits into
indykoning:masterfrom
johanzander:async-separate-files

Conversation

@johanzander

Copy link
Copy Markdown
Collaborator

Summary

  • Adds async API classes as separate files alongside existing sync code (OpenAI SDK pattern)
  • Sync code is completely untouchedrequests remains the sync HTTP library
  • Async classes use httpx as an optional dependency (pip install growattServer[async])
  • Lazy imports via __getattr__ so httpx is never required unless async classes are used

New files

File Class Async copy of
growattServer/async_base_api.py AsyncGrowattApi GrowattApi
growattServer/open_api_v1/async_open_api_v1.py AsyncOpenApiV1 OpenApiV1
growattServer/open_api_v1/devices/async_min.py AsyncMin Min
growattServer/open_api_v1/devices/async_sph.py AsyncSph Sph

Usage

from growattServer import AsyncOpenApiV1

async with AsyncOpenApiV1(token="your_token") as api:
    plants = await api.plant_list()

Trade-offs vs #150

This PR (separate files) #150 (shared base + httpx)
Breaking change No Yes (requests to httpx)
Code duplication Yes (~4 files duplicated) No
Complexity Low (straightforward copies) Higher (coroutine passthrough)
Sync HTTP library requests (unchanged) httpx

This is an alternative to #150 for discussion on #149. The main advantage is that it is non-breaking — existing consumers (including Home Assistant) continue to work without any changes.

Test plan

  • Verify sync imports still work without httpx installed
  • Verify async imports work with httpx installed
  • Verify AsyncGrowattApi and AsyncOpenApiV1 instantiate correctly
  • Verify get_device() returns AsyncMin/AsyncSph correctly
  • Integration test with real Growatt API (manual)

🤖 Generated with Claude Code

johanzander and others added 2 commits June 3, 2026 23:35
Non-breaking addition of async API classes using the separate-files
pattern (similar to the OpenAI SDK). Sync code remains untouched on
requests; async classes use httpx as an optional dependency.

New files:
- async_base_api.py: AsyncGrowattApi (async copy of GrowattApi)
- open_api_v1/async_open_api_v1.py: AsyncOpenApiV1
- open_api_v1/devices/async_min.py: AsyncMin
- open_api_v1/devices/async_sph.py: AsyncSph

Install with: pip install growattServer[async]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add noqa: PLC0415 for lazy imports inside __getattr__
- Extract f-string from AttributeError to variable (EM102)
- Remove unused noqa: S324 directive from async_base_api.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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