Skip to content

Commit

Permalink
Increase timeout for fetching buienradar weather data (home-assistant…
Browse files Browse the repository at this point in the history
…#124597)

Increase timeout for fetching weather data
  • Loading branch information
mjj4791 authored and bramkragten committed Sep 3, 2024
1 parent b81d7a0 commit 005be4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
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

0 comments on commit 005be4e

Please sign in to comment.