home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.95k stars 30.52k forks source link

Unexpected error fetching openweathermap data #119650

Open blomnik opened 4 months ago

blomnik commented 4 months ago

The problem

Suddenly, OpenWeatherMap intergration was broken. I use free v3.0 API key

Core 2024.6.2 Supervisor 2024.06.0 Operating System 12.1 Interface 20240610.0

Логгер: homeassistant.components.openweathermap.coordinator
Джерело: helpers/update_coordinator.py:312
інтеграції: OpenWeatherMap (документація, проблеми)
Вперше відбулося: 13 червня 2024 р. о 23:33:37 (60 випадки)
Востаннє записано: 01:50:26

Unexpected error fetching openweathermap data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/openweathermap/coordinator.py", line 78, in _async_update_data
    weather_report = await self._owm_client.get_weather(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyopenweathermap/owm_client.py", line 42, in get_weather
    current = DataConverter.to_current_weather(json_response['current'])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyopenweathermap/data_converter.py", line 18, in to_current_weather
    visibility=json['visibility'],
               ~~~~^^^^^^^^^^^^^^
KeyError: 'visibility'

What version of Home Assistant Core has the issue?

2024.6.2

What was the last working version of Home Assistant Core?

2024.6.1

What type of installation are you running?

Home Assistant OS

Integration causing the issue

OpenWeatherMap

Link to integration documentation on our website

https://www.home-assistant.io/integrations/openweathermap

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @fabaff, @freekode, @nzapponi, mind taking a look at this issue 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 issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign openweathermap` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


openweathermap documentation openweathermap source (message by IssueLinks)

LordLinhey commented 4 months ago

Actually blomnik, the free version uses a cut down v2.5 api not to be confused with the OneCallv2.5. The OneCall is moving to v3, the free version is available to anyone as a new user, even now. Why there is no support for the Freemium version in the integration is the question???? The way around it is to use Node-red to collect the data and send it to HA and forget the integration

blomnik commented 4 months ago

Thanks! It's magic, but a problem was fixed by itself after a several hours. Now it works fine.

uhoreg commented 4 months ago

I'm currently hitting this issue. It looks like the Home Assistant integration is expecting a visibility property to be there, but it isn't always returned by OpenWeatherMap.

broyuken commented 4 months ago

I’m noticing this as well, was working fine under 2024.6.3 but broke as soon as I upgraded to 2024.6.4

grayfrost90 commented 4 months ago

mine was like this, but seems to have fixed itself today without me doing anything (I think)

uhoreg commented 4 months ago

It looks like this should be fixed by https://github.com/freekode/pyopenweathermap/pull/8 so presumably it will be fixed in the next release of Home Assistant

smarthomefamilyverrips commented 3 months ago

Same here

andyblac commented 3 months ago

how can I add this fix manually ?, as I can't update to 2024.07 due the Database issue.

LanceMcCarthy commented 2 months ago

This only started affecting me after updating to 2024.8

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/openweathermap/coordinator.py", line 78, in _async_update_data
    weather_report = await self._owm_client.get_weather(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyopenweathermap/owm_client.py", line 42, in get_weather
    current = DataConverter.to_current_weather(json_response['current'])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyopenweathermap/data_converter.py", line 18, in to_current_weather
    visibility=json['visibility'],
               ~~~~^^^^^^^^^^^^^^
KeyError: 'visibility'

~Regardless of the cause, that json['visibility'] key-value check should at least be guarded against exception.~

Never mind, I see that's exactly what he did :D https://github.com/freekode/pyopenweathermap/pull/8/files

LanceMcCarthy commented 2 months ago

Confirmed fixed after updating to 2024.8.1

cc @blomnik @freekode