Skip to content

Add support for OpenWeatherMap One Call API v4.0#176620

Closed
pike00 wants to merge 2 commits into
home-assistant:devfrom
pike00:fix-owm-v4-issue-174333
Closed

Add support for OpenWeatherMap One Call API v4.0#176620
pike00 wants to merge 2 commits into
home-assistant:devfrom
pike00:fix-owm-v4-issue-174333

Conversation

@pike00

@pike00 pike00 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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 pyopenweathermap library 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 OWMOneCallClient inside the integration to dynamically target the 4.0 endpoint.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings July 16, 2026 14:29
@pike00
pike00 requested a review from fabaff as a code owner July 16, 2026 14:29
@home-assistant home-assistant Bot added bugfix cla-signed has-tests integration: openweathermap Top 200 Integration is ranked within the top 200 by usage labels Jul 16, 2026
@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @fabaff, @freekode, @nzapponi, @wittypluck, mind taking a look at this pull request as it has been labeled with an integration (openweathermap) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of openweathermap can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign openweathermap Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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,
Copilot AI review requested due to automatic review settings July 16, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

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)
@pike00

pike00 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

I have opened an upstream PR to add this functionality to pyopenweathermap natively in order to adhere to Home Assistant's architecture guidelines: freekode/pyopenweathermap#22. Once that is merged and released, I will open a new PR here to bump the dependency.

@pike00 pike00 closed this Jul 16, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenWeatherMap integration v3.0 mode incompatible with One Call API 4.0 subscriptions

3 participants