Add support for OpenWeatherMap One Call API v4.0#176620
Closed
pike00 wants to merge 2 commits into
Closed
Conversation
Contributor
|
Hey there @fabaff, @freekode, @nzapponi, @wittypluck, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OpenWeatherMap One Call API v4.0 as a selectable integration mode.
Changes:
- Adds v4.0 mode and client routing.
- Enables v4.0 weather and forecast features.
- Extends config-flow, entity, and snapshot tests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/openweathermap/__init__.py |
Creates mode-specific clients. |
homeassistant/components/openweathermap/const.py |
Defines v4.0 mode. |
homeassistant/components/openweathermap/coordinator.py |
Routes v4.0 weather updates. |
homeassistant/components/openweathermap/strings.json |
Updates forecast error text. |
homeassistant/components/openweathermap/utils.py |
Implements the v4.0 client. |
homeassistant/components/openweathermap/weather.py |
Enables v4.0 forecasts. |
tests/components/openweathermap/conftest.py |
Updates client mocking. |
tests/components/openweathermap/test_config_flow.py |
Covers v4.0 configuration. |
tests/components/openweathermap/test_sensor.py |
Covers v4.0 sensors. |
tests/components/openweathermap/test_weather.py |
Covers v4.0 weather behavior. |
tests/components/openweathermap/snapshots/test_sensor.ambr |
Adds v4.0 sensor snapshots. |
tests/components/openweathermap/snapshots/test_weather.ambr |
Adds v4.0 weather snapshots. |
Comment on lines
+15
to
+20
| class OWMOneCallClientV4(OWMOneCallClient): | ||
| """OWM client for One Call API 4.0.""" | ||
|
|
||
| def _get_url(self, lat: float, lon: float) -> str: | ||
| return ( | ||
| "https://api.openweathermap.org/data/4.0/onecall?" |
Comment on lines
+31
to
+32
| if mode == OWM_MODE_V40: | ||
| return OWMOneCallClientV4(api_key, mode, lang=language) |
| OWM_MODE_AIRPOLLUTION = "air_pollution" | ||
| OWM_MODES = [ | ||
| OWM_MODE_V30, | ||
| OWM_MODE_V40, |
Comment on lines
+15
to
+18
| class OWMOneCallClientV4(OWMOneCallClient): | ||
| """OWM client for One Call API 4.0.""" | ||
|
|
||
| def _get_url(self, lat: float, lon: float) -> str: |
Comment on lines
+31
to
+32
| if mode == OWM_MODE_V40: | ||
| return OWMOneCallClientV4(api_key, mode, lang=language) |
| OWM_MODE_AIRPOLLUTION = "air_pollution" | ||
| OWM_MODES = [ | ||
| OWM_MODE_V30, | ||
| OWM_MODE_V40, |
| def get_owm_client(api_key: str, mode: str, language: str = DEFAULT_LANGUAGE) -> Any: | ||
| """Get the OWM client.""" | ||
| if mode == OWM_MODE_V40: | ||
| return OWMOneCallClientV4(api_key, mode, lang=language) |
Contributor
Author
|
I have opened an upstream PR to add this functionality to |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Proposed change
This PR adds support for the OpenWeatherMap One Call API v4.0 endpoint, fixing #174333.
Starting August 2024, new OpenWeatherMap accounts can only subscribe to the v4.0 API (One Call by Call plan), and the legacy v3.0 subscription is no longer available.
Because the
pyopenweathermaplibrary currently hardcodes the 3.0 endpoint, users with new v4.0 keys receive a 401 Unauthorized error when attempting to use this integration.To fix this without waiting for an upstream library update, this PR subclasses
OWMOneCallClientinside the integration to dynamically target the 4.0 endpoint.Type of change
Additional information
Checklist
ruff format homeassistant tests)To help with the load of incoming pull requests: