diff --git a/examples/estimate.py b/examples/estimate.py index 583b52d..5dd8424 100644 --- a/examples/estimate.py +++ b/examples/estimate.py @@ -3,7 +3,7 @@ from datetime import datetime, timezone, timedelta from pprint import pprint -from forecast_solar import ForecastSolar, ForecastSolarRatelimit +from forecast_solar import ForecastSolar, ForecastSolarRatelimitError async def main(): @@ -19,7 +19,7 @@ async def main(): ) as forecast: try: estimate = await forecast.estimate() - except ForecastSolarRatelimit as err: + except ForecastSolarRatelimitError as err: print("Ratelimit reached") print(f"Rate limit resets at {err.reset_at}") reset_period = err.reset_at - datetime.now(timezone.utc) diff --git a/src/forecast_solar/__init__.py b/src/forecast_solar/__init__.py index 5aa87f7..799f511 100644 --- a/src/forecast_solar/__init__.py +++ b/src/forecast_solar/__init__.py @@ -6,7 +6,7 @@ ForecastSolarConfigError, ForecastSolarAuthenticationError, ForecastSolarRequestError, - ForecastSolarRatelimit, + ForecastSolarRatelimitError, ) from .models import Estimate, AccountType, Ratelimit from .forecast_solar import ForecastSolar @@ -19,7 +19,7 @@ "ForecastSolarConfigError", "ForecastSolarConnectionError", "ForecastSolarError", - "ForecastSolarRatelimit", + "ForecastSolarRatelimitError", "ForecastSolarRequestError", "Ratelimit", ] diff --git a/src/forecast_solar/exceptions.py b/src/forecast_solar/exceptions.py index 440a54c..e1c1cd9 100644 --- a/src/forecast_solar/exceptions.py +++ b/src/forecast_solar/exceptions.py @@ -45,7 +45,7 @@ def __init__(self, data: dict) -> None: self.code = data["code"] -class ForecastSolarRatelimit(ForecastSolarRequestError): +class ForecastSolarRatelimitError(ForecastSolarRequestError): """Forecast.Solar maximum number of requests reached exception.""" def __init__(self, data: dict) -> None: diff --git a/src/forecast_solar/forecast_solar.py b/src/forecast_solar/forecast_solar.py index 6d9dd5c..f5c2cdd 100644 --- a/src/forecast_solar/forecast_solar.py +++ b/src/forecast_solar/forecast_solar.py @@ -15,7 +15,7 @@ ForecastSolarConfigError, ForecastSolarConnectionError, ForecastSolarError, - ForecastSolarRatelimit, + ForecastSolarRatelimitError, ForecastSolarRequestError, ) from .models import Estimate, Ratelimit @@ -74,7 +74,7 @@ async def _request( Forecast.Solar API. ForecastSolarRequestError: There is something wrong with the variables used in the request. - ForecastSolarRatelimit: The number of requests has exceeded + ForecastSolarRatelimitError: The number of requests has exceeded the rate limit of the Forecast.Solar API. """ @@ -132,7 +132,7 @@ async def _request( if response.status == 429: data = await response.json() - raise ForecastSolarRatelimit(data["message"]) + raise ForecastSolarRatelimitError(data["message"]) if rate_limit and response.status < 500: self.ratelimit = Ratelimit.from_response(response) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index c18ae6b..5d6b3fd 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -5,7 +5,7 @@ from forecast_solar import ( ForecastSolar, - ForecastSolarRatelimit, + ForecastSolarRatelimitError, ForecastSolarConfigError, ForecastSolarAuthenticationError, ForecastSolarRequestError, @@ -103,7 +103,7 @@ async def test_status_429( text=load_fixtures("ratelimit.json"), ), ) - with pytest.raises(ForecastSolarRatelimit): + with pytest.raises(ForecastSolarRatelimitError): assert await forecast_client._request("test")