Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout for fetching buienradar weather data #124597

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Increase timeout for fetching weather data
  • Loading branch information
mjj4791 committed Sep 1, 2024
commit 3b21ee63b789527b2e8259680e7198a56cb2fa1d
1 change: 1 addition & 0 deletions homeassistant/components/buienradar/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

DOMAIN = "buienradar"

DEFAULT_TIMEOUT = 60
DEFAULT_TIMEFRAME = 60

DEFAULT_DIMENSION = 700
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/buienradar/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,12 +27,12 @@
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__)
Expand All @@ -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
Expand Down Expand Up @@ -93,9 +93,9 @@ async def get_data(self, url):
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/buienradar/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)'}"
Expand Down