diff --git a/homeassistant/components/buienradar/manifest.json b/homeassistant/components/buienradar/manifest.json index 23e282c34bb..5f604322b16 100644 --- a/homeassistant/components/buienradar/manifest.json +++ b/homeassistant/components/buienradar/manifest.json @@ -2,7 +2,7 @@ "domain": "buienradar", "name": "Buienradar", "documentation": "https://www.home-assistant.io/integrations/buienradar", - "requirements": ["buienradar==1.0.1"], + "requirements": ["buienradar==1.0.4"], "dependencies": [], "codeowners": ["@mjj4791", "@ties"] } diff --git a/homeassistant/components/buienradar/util.py b/homeassistant/components/buienradar/util.py index 37c518cef7a..7d16f072b98 100644 --- a/homeassistant/components/buienradar/util.py +++ b/homeassistant/components/buienradar/util.py @@ -32,12 +32,31 @@ from homeassistant.util import dt as dt_util from .const import SCHEDULE_NOK, SCHEDULE_OK +__all__ = ["BrData"] _LOGGER = logging.getLogger(__name__) +""" +Log at WARN level after WARN_THRESHOLD failures, otherwise log at +DEBUG level. +""" +WARN_THRESHOLD = 4 + + +def threshold_log(count: int, *args, **kwargs) -> None: + """Log at warn level after WARN_THRESHOLD failures, debug otherwise.""" + if count >= WARN_THRESHOLD: + _LOGGER.warning(*args, **kwargs) + else: + _LOGGER.debug(*args, **kwargs) + class BrData: """Get the latest data and updates the states.""" + # Initialize to warn immediately if the first call fails. + load_error_count: int = WARN_THRESHOLD + rain_error_count: int = WARN_THRESHOLD + def __init__(self, hass, coordinates, timeframe, devices): """Initialize the data object.""" self.devices = devices @@ -96,7 +115,9 @@ class BrData: if content.get(SUCCESS) is not True: # unable to get the data - _LOGGER.warning( + self.load_error_count += 1 + threshold_log( + self.load_error_count, "Unable to retrieve json data from Buienradar." "(Msg: %s, status: %s,)", content.get(MESSAGE), @@ -105,6 +126,7 @@ class BrData: # schedule new call await self.schedule_update(SCHEDULE_NOK) return + self.load_error_count = 0 # rounding coordinates prevents unnecessary redirects/calls lat = self.coordinates[CONF_LATITUDE] @@ -113,15 +135,18 @@ class BrData: raincontent = await self.get_data(rainurl) if raincontent.get(SUCCESS) is not True: + self.rain_error_count += 1 # unable to get the data - _LOGGER.warning( - "Unable to retrieve raindata from Buienradar. (Msg: %s, status: %s)", + threshold_log( + self.rain_error_count, + "Unable to retrieve rain data from Buienradar." "(Msg: %s, status: %s)", raincontent.get(MESSAGE), raincontent.get(STATUS_CODE), ) # schedule new call await self.schedule_update(SCHEDULE_NOK) return + self.rain_error_count = 0 result = parse_data( content.get(CONTENT), diff --git a/requirements_all.txt b/requirements_all.txt index 3adff8a4743..3133c23bde8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -368,7 +368,7 @@ bthomehub5-devicelist==0.1.1 btsmarthub_devicelist==0.1.3 # homeassistant.components.buienradar -buienradar==1.0.1 +buienradar==1.0.4 # homeassistant.components.caldav caldav==0.6.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c7f59369b26..866c7eaa9c2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -130,7 +130,7 @@ broadlink==0.12.0 brother==0.1.8 # homeassistant.components.buienradar -buienradar==1.0.1 +buienradar==1.0.4 # homeassistant.components.caldav caldav==0.6.1