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