Fix incorrect type annotations in OpenApiV1 plant_id and plant_list - #159
Merged
johanzander merged 2 commits intoAug 1, 2026
Merged
Conversation
GrowattApi annotates plant_id as str on every method that takes one, but
OpenApiV1 annotates it as int on plant_details, plant_energy_overview,
plant_power_overview, plant_energy_history and device_list.
All five only pass the value through to params={"plant_id": plant_id},
so str has always worked at runtime; only the annotation disagreed.
The mismatch forces callers that hold a plant id as a str to either
suppress arg-type errors or coerce with int(), which breaks on
non-numeric ids.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
plant_list is annotated as returning dict[str, Any], but the fallback
when the response has no "back" key is [], so the empty case returns a
list and contradicts the annotation.
Callers that follow the annotation and do plant_info.get("data") hit an
AttributeError on that path, forcing an isinstance() guard purely to
defend against the default. plant_detail on the same endpoint family
already defaults to {}.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
great! looking forward to the next release! |
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.
Closes #157.
1. V1
plant_idannotationsGrowattApiannotatesplant_idasstron every method that takes one, butOpenApiV1annotates it asintonplant_details,plant_energy_overview,plant_power_overview,plant_energy_historyanddevice_list.All five only pass the value through to
params={"plant_id": plant_id}, sostrhas always worked at runtime — only the annotation disagreed. Since 2.2.0 shippedpy.typed, the mismatch is now visible to consumers: a caller holding a plant id as astr(which is what the base class returns, and what the ID naturally is) must either suppressarg-typeerrors or coerce withint()— and coercing crashes on non-numeric ids.The
# type: ignore[override]ondevice_listis left in place — it covers the return type differing from the base class (dictvslist), which is unrelated toplant_id.2.
plant_listempty-case return#153 corrected the
plant_listannotation todict[str, Any], but the fallback when the response has nobackkey is still[]:So the empty case returns a list and contradicts the annotation. A caller that follows the annotation and does
plant_info.get("data")hits anAttributeErroron that path, which forces anisinstance()guard purely to defend against the default.plant_detail, on the same endpoint family, already defaults to{}.Scope
Both changes are annotation-consistency fixes; the only runtime change is the
{}default in the empty-response path, which replaces anAttributeErrorwith a falsy dict.Release note
Together with #153 — merged but unreleased, as 2.2.0 shipped one day before it landed — this unblocks removing the remaining type suppressions and defensive guards in the Home Assistant
growatt_serverintegration (home-assistant/core#173220). Verified locally: with this branch installed, that integration's# type: ignore[arg-type]comments delete cleanly with mypy passing and its full test suite green. A 2.3.0 covering both PRs would let those changes land.