Fix plant_id type annotations in OpenApiV1 (int -> str) - #158
Merged
Conversation
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.
indykoning
approved these changes
Aug 1, 2026
indykoning
approved these changes
Aug 1, 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.
Follow-up to the
py.typedtyping added in 2.2.0. A few annotations didn't match the actual runtime shapes / call sites, forcing downstream consumers (Home Assistant) into# type: ignoreandAny. Fixing them at the source.Fixes #157.
Changes
OpenApiV1plant_id: int→str(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 matchesGrowattApi's own signatures and how callers pass them. Theintannotations made mypy reject the (correct)strarguments in consumers.GrowattApi.plant_listfallback default[]→{}. The return type is already annotateddict[str, Any]onmaster, but the fallback still returned alistwhen thebackkey is absent.{}matches the declared type and the real shape ({"data": [...], "totalData": {...}}).Notes
OpenApiV1.device_listkeeps its# type: ignore[override]: it still returnsdictwhile the baseGrowattApi.device_listreturnslist, so it remains an intentional LSP divergence (two different APIs). Theint→strchange only aligns the parameter.plant_listreturn type and docstring were already corrected todictonmaster, so they're not part of this diff — only the fallback default remained.Verification
mypy --ignore-missing-imports growattServer/— clean.ruff check growattServer/— clean.