Small performance improvements to config entry setup retry (#110448)

* Small performance improvements to config entry setup retry

- cache some properties that never change
- avoid loader.async_get_integration when we already have it
- avoid multiple integration.domain checks

* tweaks
This commit is contained in:
J. Nick Koston 2024-02-13 06:28:52 -06:00 committed by GitHub
parent 6812596cd7
commit 01c3205635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 17 deletions

View File

@ -385,12 +385,12 @@ class ConfigEntry:
if self.source == SOURCE_IGNORE or self.disabled_by:
return
if integration is None:
if integration is None and not (integration := self._integration_for_domain):
integration = await loader.async_get_integration(hass, self.domain)
self._integration_for_domain = integration
# Only store setup result as state if it was not forwarded.
if self.domain == integration.domain:
if domain_is_integration := self.domain == integration.domain:
self._async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
if self.supports_unload is None:
@ -409,13 +409,13 @@ class ConfigEntry:
self.domain,
err,
)
if self.domain == integration.domain:
if domain_is_integration:
self._async_set_state(
hass, ConfigEntryState.SETUP_ERROR, "Import error"
)
return
if self.domain == integration.domain:
if domain_is_integration:
try:
integration.get_platform("config_flow")
except ImportError as err:
@ -475,12 +475,12 @@ class ConfigEntry:
self.async_start_reauth(hass)
result = False
except ConfigEntryNotReady as exc:
self._async_set_state(hass, ConfigEntryState.SETUP_RETRY, str(exc) or None)
message = str(exc)
self._async_set_state(hass, ConfigEntryState.SETUP_RETRY, message or None)
wait_time = 2 ** min(self._tries, 4) * 5 + (
randint(RANDOM_MICROSECOND_MIN, RANDOM_MICROSECOND_MAX) / 1000000
)
self._tries += 1
message = str(exc)
ready_message = f"ready yet: {message}" if message else "ready yet"
_LOGGER.debug(
(
@ -513,7 +513,7 @@ class ConfigEntry:
result = False
# Only store setup result as state if it was not forwarded.
if self.domain != integration.domain:
if not domain_is_integration:
return
#

View File

@ -665,52 +665,52 @@ class Integration:
"""Return reason integration is disabled."""
return self.manifest.get("disabled")
@property
@cached_property
def domain(self) -> str:
"""Return domain."""
return self.manifest["domain"]
@property
@cached_property
def dependencies(self) -> list[str]:
"""Return dependencies."""
return self.manifest.get("dependencies", [])
@property
@cached_property
def after_dependencies(self) -> list[str]:
"""Return after_dependencies."""
return self.manifest.get("after_dependencies", [])
@property
@cached_property
def requirements(self) -> list[str]:
"""Return requirements."""
return self.manifest.get("requirements", [])
@property
@cached_property
def config_flow(self) -> bool:
"""Return config_flow."""
return self.manifest.get("config_flow") or False
@property
@cached_property
def documentation(self) -> str | None:
"""Return documentation."""
return self.manifest.get("documentation")
@property
@cached_property
def issue_tracker(self) -> str | None:
"""Return issue tracker link."""
return self.manifest.get("issue_tracker")
@property
@cached_property
def loggers(self) -> list[str] | None:
"""Return list of loggers used by the integration."""
return self.manifest.get("loggers")
@property
@cached_property
def quality_scale(self) -> str | None:
"""Return Integration Quality Scale."""
return self.manifest.get("quality_scale")
@property
@cached_property
def iot_class(self) -> str | None:
"""Return the integration IoT Class."""
return self.manifest.get("iot_class")