Reduce log level for initial error and bump library version (#32381)

* Reduce log level for initial error and bump library version

  * Use new buienradar library version which reduces the log level
    for some types of warnings.
  * Initially logs at a lower level and only logs at WARN for repeated
    errors.

This should serve to reduce confusion with users such as in
issue #32301.

* Fix linter error with new linter settings.

* Fix linter warning

* Update homeassistant/components/buienradar/util.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Paulus Schoutsen 2020-03-04 15:32:44 -08:00 committed by GitHub
parent 15a5cebd5f
commit 76fec90fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 6 deletions

View File

@ -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"]
}

View File

@ -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),

View File

@ -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

View File

@ -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