Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01c3205

Browse files
authored
Small performance improvements to config entry setup retry (home-assistant#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
1 parent 6812596 commit 01c3205

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

‎homeassistant/config_entries.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,12 @@ async def async_setup(
385385
if self.source == SOURCE_IGNORE or self.disabled_by:
386386
return
387387

388-
if integration is None:
388+
if integration is Noneandnot (integration:=self._integration_for_domain):
389389
integration = await loader.async_get_integration(hass, self.domain)
390390
self._integration_for_domain = integration
391391

392392
# Only store setup result as state if it was not forwarded.
393-
if self.domain == integration.domain:
393+
if domain_is_integration:=self.domain == integration.domain:
394394
self._async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
395395

396396
if self.supports_unload is None:
@@ -409,13 +409,13 @@ async def async_setup(
409409
self.domain,
410410
err,
411411
)
412-
if self.domain==integration.domain:
412+
if domain_is_integration:
413413
self._async_set_state(
414414
hass, ConfigEntryState.SETUP_ERROR, "Import error"
415415
)
416416
return
417417

418-
if self.domain==integration.domain:
418+
if domain_is_integration:
419419
try:
420420
integration.get_platform("config_flow")
421421
except ImportError as err:
@@ -475,12 +475,12 @@ async def async_setup(
475475
self.async_start_reauth(hass)
476476
result = False
477477
except ConfigEntryNotReady as exc:
478-
self._async_set_state(hass, ConfigEntryState.SETUP_RETRY, str(exc) or None)
478+
message = str(exc)
479+
self._async_set_state(hass, ConfigEntryState.SETUP_RETRY, message or None)
479480
wait_time = 2 ** min(self._tries, 4) * 5 + (
480481
randint(RANDOM_MICROSECOND_MIN, RANDOM_MICROSECOND_MAX) / 1000000
481482
)
482483
self._tries += 1
483-
message = str(exc)
484484
ready_message = f"ready yet: {message}" if message else "ready yet"
485485
_LOGGER.debug(
486486
(
@@ -513,7 +513,7 @@ async def async_setup(
513513
result = False
514514

515515
# Only store setup result as state if it was not forwarded.
516-
if self.domain!=integration.domain:
516+
if notdomain_is_integration:
517517
return
518518

519519
#

‎homeassistant/loader.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,52 +665,52 @@ def disabled(self) -> str | None:
665665
"""Return reason integration is disabled."""
666666
return self.manifest.get("disabled")
667667

668-
@property
668+
@cached_property
669669
def domain(self) -> str:
670670
"""Return domain."""
671671
return self.manifest["domain"]
672672

673-
@property
673+
@cached_property
674674
def dependencies(self) -> list[str]:
675675
"""Return dependencies."""
676676
return self.manifest.get("dependencies", [])
677677

678-
@property
678+
@cached_property
679679
def after_dependencies(self) -> list[str]:
680680
"""Return after_dependencies."""
681681
return self.manifest.get("after_dependencies", [])
682682

683-
@property
683+
@cached_property
684684
def requirements(self) -> list[str]:
685685
"""Return requirements."""
686686
return self.manifest.get("requirements", [])
687687

688-
@property
688+
@cached_property
689689
def config_flow(self) -> bool:
690690
"""Return config_flow."""
691691
return self.manifest.get("config_flow") or False
692692

693-
@property
693+
@cached_property
694694
def documentation(self) -> str | None:
695695
"""Return documentation."""
696696
return self.manifest.get("documentation")
697697

698-
@property
698+
@cached_property
699699
def issue_tracker(self) -> str | None:
700700
"""Return issue tracker link."""
701701
return self.manifest.get("issue_tracker")
702702

703-
@property
703+
@cached_property
704704
def loggers(self) -> list[str] | None:
705705
"""Return list of loggers used by the integration."""
706706
return self.manifest.get("loggers")
707707

708-
@property
708+
@cached_property
709709
def quality_scale(self) -> str | None:
710710
"""Return Integration Quality Scale."""
711711
return self.manifest.get("quality_scale")
712712

713-
@property
713+
@cached_property
714714
def iot_class(self) -> str | None:
715715
"""Return the integration IoT Class."""
716716
return self.manifest.get("iot_class")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /