Now that the library is type-checked by consumers (py.typed, 2.2.0), a few annotations turn out not to match the actual runtime shapes / call sites. This is follow-up on the typing I added — fixing it at the source so downstream consumers (Home Assistant) don't have to work around it with # type: ignore / Any.
1. GrowattApi.plant_list return type (base_api.py)
def plant_list(self, user_id: str) -> list[dict[str, Any]]:
...
return response.json().get("back", [])
For the classic PlantListAPI.do endpoint, back is a dict, not a list:
{
"data": [
{"plantId": "123456", "plantName": "...", "todayEnergy": "2.6 kWh", ...},
],
"totalData": {...},
}
Callers index it as plant_info["data"][0]["plantId"], which only works on a dict. The current list[dict[str, Any]] annotation makes mypy reject "data" in plant_info (comparison-overlap) and plant_info["data"] (call-overload).
- Fix:
-> dict[str, Any], and change the fallback default from [] to {}.
- The docstring ("Returns: list ...") should be updated to say dict.
2. OpenApiV1.device_list parameter type (open_api_v1/__init__.py)
def device_list(self, plant_id: int) -> dict[str, Any]: # type: ignore[override]
GrowattApi.device_list uses plant_id: str, and plant IDs are opaque string identifiers throughout the API. The int here mismatches the base class — which is why the # type: ignore[override] is needed — and forces str-passing callers to cast.
- Fix:
plant_id: str, which also removes the # type: ignore[override].
3. OpenApiV1.plant_energy_overview parameter type (open_api_v1/__init__.py)
def plant_energy_overview(self, plant_id: int) -> dict[str, Any]:
Same as above — callers pass a str plant ID.
I'll follow up with a PR.
Now that the library is type-checked by consumers (
py.typed, 2.2.0), a few annotations turn out not to match the actual runtime shapes / call sites. This is follow-up on the typing I added — fixing it at the source so downstream consumers (Home Assistant) don't have to work around it with# type: ignore/Any.1.
GrowattApi.plant_listreturn type (base_api.py)For the classic
PlantListAPI.doendpoint,backis a dict, not a list:{ "data": [ {"plantId": "123456", "plantName": "...", "todayEnergy": "2.6 kWh", ...}, ], "totalData": {...}, }Callers index it as
plant_info["data"][0]["plantId"], which only works on a dict. The currentlist[dict[str, Any]]annotation makes mypy reject"data" in plant_info(comparison-overlap) andplant_info["data"](call-overload).-> dict[str, Any], and change the fallback default from[]to{}.2.
OpenApiV1.device_listparameter type (open_api_v1/__init__.py)GrowattApi.device_listusesplant_id: str, and plant IDs are opaque string identifiers throughout the API. Theinthere mismatches the base class — which is why the# type: ignore[override]is needed — and forcesstr-passing callers to cast.plant_id: str, which also removes the# type: ignore[override].3.
OpenApiV1.plant_energy_overviewparameter type (open_api_v1/__init__.py)Same as above — callers pass a
strplant ID.plant_id: str.I'll follow up with a PR.