Increase timeout for fetching buienradar weather data (#124597)

Increase timeout for fetching weather data
This commit is contained in:
MJJ 2024-09-03 16:50:30 +02:00 committed by GitHub
parent 96be3e2505
commit 42ed7fbb0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View File

@ -2,6 +2,7 @@
DOMAIN = "buienradar"
DEFAULT_TIMEOUT = 60
DEFAULT_TIMEFRAME = 60
DEFAULT_DIMENSION = 700

View File

@ -1,9 +1,9 @@
"""Shared utilities for different supported platforms."""
from asyncio import timeout
from datetime import datetime, timedelta
from http import HTTPStatus
import logging
from typing import Any
import aiohttp
from buienradar.buienradar import parse_data
@ -27,12 +27,12 @@ from buienradar.constants import (
from buienradar.urls import JSON_FEED_URL, json_precipitation_forecast_url
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import CALLBACK_TYPE, callback
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.util import dt as dt_util
from .const import SCHEDULE_NOK, SCHEDULE_OK
from .const import DEFAULT_TIMEOUT, SCHEDULE_NOK, SCHEDULE_OK
__all__ = ["BrData"]
_LOGGER = logging.getLogger(__name__)
@ -59,10 +59,10 @@ class BrData:
load_error_count: int = WARN_THRESHOLD
rain_error_count: int = WARN_THRESHOLD
def __init__(self, hass, coordinates, timeframe, devices):
def __init__(self, hass: HomeAssistant, coordinates, timeframe, devices) -> None:
"""Initialize the data object."""
self.devices = devices
self.data = {}
self.data: dict[str, Any] | None = {}
self.hass = hass
self.coordinates = coordinates
self.timeframe = timeframe
@ -93,9 +93,9 @@ class BrData:
resp = None
try:
websession = async_get_clientsession(self.hass)
async with timeout(10):
resp = await websession.get(url)
async with websession.get(
url, timeout=aiohttp.ClientTimeout(total=DEFAULT_TIMEOUT)
) as resp:
result[STATUS_CODE] = resp.status
result[CONTENT] = await resp.text()
if resp.status == HTTPStatus.OK:

View File

@ -130,7 +130,7 @@ class BrWeather(WeatherEntity):
_attr_should_poll = False
_attr_supported_features = WeatherEntityFeature.FORECAST_DAILY
def __init__(self, config, coordinates):
def __init__(self, config, coordinates) -> None:
"""Initialize the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME, "Buienradar")
self._attr_name = self._stationname or f"BR {'(unknown station)'}"