Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/pyopenweathermap/client/onecall_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ async def validate_key(self) -> bool:
return False

def _get_url(self, lat, lon):
return (f"{API_URL}?"
api_url = 'https://api.openweathermap.org/data/3.0/onecall'
if getattr(self, 'api_version', None) == 'v4.0':

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can't be none, you can use normal self here

api_url = 'https://api.openweathermap.org/data/4.0/onecall'
return (f"{api_url}?"
f"lat={lat}&"
f"lon={lon}&"
f"appid={self.api_key}&"
Expand Down
2 changes: 1 addition & 1 deletion src/pyopenweathermap/client/owm_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create_owm_client(api_key, api_type, units="metric", lang='en'):
logger = logging.getLogger(__name__)

logger.info('Initializing OWMClient with api type: ' + str(api_type))
if api_type == 'v3.0':
if api_type == 'v3.0' or api_type == 'v4.0':
return OWMOneCallClient(api_key, api_type, units, lang)
if api_type == 'current' or api_type == 'forecast':
return OWMFreeClient(api_key, api_type, units, lang)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ async def test_api_30():
assert report.daily_forecast[0].condition.id is not None


@pytest.mark.network
@pytest.mark.asyncio
async def test_api_40():
api_key = os.getenv('OWM_API_KEY')
client = create_owm_client(api_key, 'v4.0')
report = await client.get_weather(LATITUDE, LONGITUDE)
assert report.current.date_time is not None
assert report.hourly_forecast[0].condition.id is not None
assert report.daily_forecast[0].condition.id is not None

@pytest.mark.network
@pytest.mark.asyncio
async def test_free_current_weather():
Expand Down Expand Up @@ -115,3 +125,9 @@ def test_forecast_deserialization():
weather = DataConverter.free_to_hourly_weather_forecast(data)
assert weather.date_time is not None
assert weather.condition.id is not None

def test_v40_url():
client = create_owm_client('fake_key', 'v4.0')
url = client._get_url(10.0, 20.0)
assert 'https://api.openweathermap.org/data/4.0/onecall' in url
assert 'fake_key' in url
Loading