From 37dbae4beb3e42ec9538805fbc405b0f27d62860 Mon Sep 17 00:00:00 2001 From: Johan Zander Date: Sun, 26 Jul 2026 21:05:39 +0000 Subject: [PATCH] Fix plant_id type annotations in OpenApiV1 (int -> str) 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. --- growattServer/base_api.py | 2 +- growattServer/open_api_v1/__init__.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/growattServer/base_api.py b/growattServer/base_api.py index 58e1085..327d9f8 100644 --- a/growattServer/base_api.py +++ b/growattServer/base_api.py @@ -198,7 +198,7 @@ def plant_list(self, user_id: str) -> dict[str, Any]: allow_redirects=False ) - return response.json().get("back", []) + return response.json().get("back", {}) def plant_detail(self, plant_id: str, timespan: Timespan, date: datetime.datetime | None = None) -> dict[str, Any]: """ diff --git a/growattServer/open_api_v1/__init__.py b/growattServer/open_api_v1/__init__.py index 5980980..7ef9cc4 100644 --- a/growattServer/open_api_v1/__init__.py +++ b/growattServer/open_api_v1/__init__.py @@ -119,12 +119,12 @@ def plant_list(self) -> dict[str, Any]: # type: ignore[override] return self.process_response(response.json(), "getting plant list") - def plant_details(self, plant_id: int) -> dict[str, Any]: + def plant_details(self, plant_id: str) -> dict[str, Any]: """ Get basic information about a power station. Args: - plant_id (int): Power Station ID + plant_id (str): Power Station ID Returns: dict: A dictionary containing the plant details. @@ -147,12 +147,12 @@ def plant_details(self, plant_id: int) -> dict[str, Any]: return self.process_response(response.json(), "getting plant details") - def plant_energy_overview(self, plant_id: int) -> dict[str, Any]: + def plant_energy_overview(self, plant_id: str) -> dict[str, Any]: """ Get an overview of a plant's energy data. Args: - plant_id (int): Power Station ID + plant_id (str): Power Station ID Returns: dict: A dictionary containing the plant energy overview. @@ -175,7 +175,7 @@ def plant_energy_overview(self, plant_id: int) -> dict[str, Any]: return self.process_response(response.json(), "getting plant energy overview") def plant_power_overview( - self, plant_id: int, day: str | date | None = None + self, plant_id: str, day: str | date | None = None ) -> dict: """ Obtain power data of a certain power station. @@ -183,7 +183,7 @@ def plant_power_overview( Get the frequency once every 5 minutes Args: - plant_id (int): Power Station ID + plant_id (str): Power Station ID day (date): Date - defaults to today in the local system timezone Returns: @@ -224,7 +224,7 @@ def plant_power_overview( def plant_energy_history( self, - plant_id: int, + plant_id: str, start_date: date | None = None, end_date: date | None = None, time_unit: str = "day", @@ -235,7 +235,7 @@ def plant_energy_history( Retrieve plant energy data for multiple days/months/years. Args: - plant_id (int): Power Station ID + plant_id (str): Power Station ID start_date (date, optional): Start Date - defaults to today in the local system timezone end_date (date, optional): End Date - defaults to today in the local system timezone time_unit (str, optional): Time unit ('day', 'month', 'year') - defaults to 'day' @@ -308,7 +308,7 @@ def plant_energy_history( return self.process_response(response.json(), "getting plant energy history") - def device_list(self, plant_id: int) -> dict[str, Any]: # type: ignore[override] + def device_list(self, plant_id: str) -> dict[str, Any]: # type: ignore[override] """ Get devices associated with plant. @@ -326,7 +326,7 @@ def device_list(self, plant_id: int) -> dict[str, Any]: # type: ignore[override 10: pbd Args: - plant_id (int): Power Station ID + plant_id (str): Power Station ID Returns: DeviceList