mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Increase timeout for fetching buienradar weather data (#124597)
Increase timeout for fetching weather data
This commit is contained in:
parent
96be3e2505
commit
42ed7fbb0d
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
DOMAIN = "buienradar"
|
DOMAIN = "buienradar"
|
||||||
|
|
||||||
|
DEFAULT_TIMEOUT = 60
|
||||||
DEFAULT_TIMEFRAME = 60
|
DEFAULT_TIMEFRAME = 60
|
||||||
|
|
||||||
DEFAULT_DIMENSION = 700
|
DEFAULT_DIMENSION = 700
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
"""Shared utilities for different supported platforms."""
|
"""Shared utilities for different supported platforms."""
|
||||||
|
|
||||||
from asyncio import timeout
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from buienradar.buienradar import parse_data
|
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 buienradar.urls import JSON_FEED_URL, json_precipitation_forecast_url
|
||||||
|
|
||||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
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.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||||
from homeassistant.util import dt as dt_util
|
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"]
|
__all__ = ["BrData"]
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -59,10 +59,10 @@ class BrData:
|
|||||||
load_error_count: int = WARN_THRESHOLD
|
load_error_count: int = WARN_THRESHOLD
|
||||||
rain_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."""
|
"""Initialize the data object."""
|
||||||
self.devices = devices
|
self.devices = devices
|
||||||
self.data = {}
|
self.data: dict[str, Any] | None = {}
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.coordinates = coordinates
|
self.coordinates = coordinates
|
||||||
self.timeframe = timeframe
|
self.timeframe = timeframe
|
||||||
@ -93,9 +93,9 @@ class BrData:
|
|||||||
resp = None
|
resp = None
|
||||||
try:
|
try:
|
||||||
websession = async_get_clientsession(self.hass)
|
websession = async_get_clientsession(self.hass)
|
||||||
async with timeout(10):
|
async with websession.get(
|
||||||
resp = await websession.get(url)
|
url, timeout=aiohttp.ClientTimeout(total=DEFAULT_TIMEOUT)
|
||||||
|
) as resp:
|
||||||
result[STATUS_CODE] = resp.status
|
result[STATUS_CODE] = resp.status
|
||||||
result[CONTENT] = await resp.text()
|
result[CONTENT] = await resp.text()
|
||||||
if resp.status == HTTPStatus.OK:
|
if resp.status == HTTPStatus.OK:
|
||||||
|
@ -130,7 +130,7 @@ class BrWeather(WeatherEntity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_supported_features = WeatherEntityFeature.FORECAST_DAILY
|
_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."""
|
"""Initialize the platform with a data instance and station name."""
|
||||||
self._stationname = config.get(CONF_NAME, "Buienradar")
|
self._stationname = config.get(CONF_NAME, "Buienradar")
|
||||||
self._attr_name = self._stationname or f"BR {'(unknown station)'}"
|
self._attr_name = self._stationname or f"BR {'(unknown station)'}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user