Avoid calling time.monotonic on coordinator refresh unless we are debugging (#70209)

This commit is contained in:
J. Nick Koston 2022-04-17 19:40:44 -10:00 committed by GitHub
parent 80ab8b465b
commit c393622b64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -183,7 +183,8 @@ class DataUpdateCoordinator(Generic[_T]):
if scheduled and self.hass.is_stopping:
return
start = monotonic()
if log_timing := self.logger.isEnabledFor(logging.DEBUG):
start = monotonic()
auth_failed = False
try:
@ -255,12 +256,13 @@ class DataUpdateCoordinator(Generic[_T]):
self.logger.info("Fetching %s data recovered", self.name)
finally:
self.logger.debug(
"Finished fetching %s data in %.3f seconds (success: %s)",
self.name,
monotonic() - start,
self.last_update_success,
)
if log_timing:
self.logger.debug(
"Finished fetching %s data in %.3f seconds (success: %s)",
self.name,
monotonic() - start,
self.last_update_success,
)
if not auth_failed and self._listeners and not self.hass.is_stopping:
self._schedule_refresh()