Skip to content

Fix plant_id type annotations in OpenApiV1 (int -> str) - #158

Merged
johanzander merged 1 commit into
masterfrom
fix-plant-id-type-annotations
Aug 1, 2026
Merged

Fix plant_id type annotations in OpenApiV1 (int -> str)#158
johanzander merged 1 commit into
masterfrom
fix-plant-id-type-annotations

Conversation

@johanzander

Copy link
Copy Markdown
Collaborator

Follow-up to the py.typed typing added in 2.2.0. A few annotations didn't match the actual runtime shapes / call sites, forcing downstream consumers (Home Assistant) into # type: ignore and Any. Fixing them at the source.

Fixes #157.

Changes

  1. OpenApiV1 plant_id: intstr (all five methods: plant_details, plant_energy_overview, plant_power_overview, plant_energy_history, device_list, plus docstrings). Plant IDs are opaque string identifiers — this matches GrowattApi's own signatures and how callers pass them. The int annotations made mypy reject the (correct) str arguments in consumers.

  2. GrowattApi.plant_list fallback default []{}. The return type is already annotated dict[str, Any] on master, but the fallback still returned a list when the back key is absent. {} matches the declared type and the real shape ({"data": [...], "totalData": {...}}).

Notes

  • OpenApiV1.device_list keeps its # type: ignore[override]: it still returns dict while the base GrowattApi.device_list returns list, so it remains an intentional LSP divergence (two different APIs). The intstr change only aligns the parameter.
  • The plant_list return type and docstring were already corrected to dict on master, so they're not part of this diff — only the fallback default remained.

Verification

  • mypy --ignore-missing-imports growattServer/ — clean.
  • ruff check growattServer/ — clean.

Plant IDs are opaque string identifiers, consistent with GrowattApi's
own signatures and how consumers pass them. The int annotations forced
callers into casts / # type: ignore.

Also fix GrowattApi.plant_list's fallback default from [] to {} to
match its dict[str, Any] return type.
@johanzander
johanzander merged commit 9672b48 into master Aug 1, 2026
4 checks passed
@johanzander
johanzander deleted the fix-plant-id-type-annotations branch August 1, 2026 20:43
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.

Incorrect type annotations in 2.2.0 (plant_list return type; OpenApiV1 plant_id: int)

2 participants