mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Prevent race when loading cloud config (#64437)
This commit is contained in:
parent
fd3b41dbe0
commit
4bcf71b1f3
@ -45,6 +45,8 @@ class CloudClient(Interface):
|
|||||||
self.alexa_user_config = alexa_user_config
|
self.alexa_user_config = alexa_user_config
|
||||||
self._alexa_config: alexa_config.CloudAlexaConfig | None = None
|
self._alexa_config: alexa_config.CloudAlexaConfig | None = None
|
||||||
self._google_config: google_config.CloudGoogleConfig | None = None
|
self._google_config: google_config.CloudGoogleConfig | None = None
|
||||||
|
self._alexa_config_init_lock = asyncio.Lock()
|
||||||
|
self._google_config_init_lock = asyncio.Lock()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def base_path(self) -> Path:
|
def base_path(self) -> Path:
|
||||||
@ -85,28 +87,44 @@ class CloudClient(Interface):
|
|||||||
async def get_alexa_config(self) -> alexa_config.CloudAlexaConfig:
|
async def get_alexa_config(self) -> alexa_config.CloudAlexaConfig:
|
||||||
"""Return Alexa config."""
|
"""Return Alexa config."""
|
||||||
if self._alexa_config is None:
|
if self._alexa_config is None:
|
||||||
assert self.cloud is not None
|
async with self._alexa_config_init_lock:
|
||||||
|
if self._alexa_config is not None:
|
||||||
|
return self._alexa_config
|
||||||
|
|
||||||
cloud_user = await self._prefs.get_cloud_user()
|
assert self.cloud is not None
|
||||||
|
|
||||||
self._alexa_config = alexa_config.CloudAlexaConfig(
|
cloud_user = await self._prefs.get_cloud_user()
|
||||||
self._hass, self.alexa_user_config, cloud_user, self._prefs, self.cloud
|
|
||||||
)
|
self._alexa_config = alexa_config.CloudAlexaConfig(
|
||||||
await self._alexa_config.async_initialize()
|
self._hass,
|
||||||
|
self.alexa_user_config,
|
||||||
|
cloud_user,
|
||||||
|
self._prefs,
|
||||||
|
self.cloud,
|
||||||
|
)
|
||||||
|
await self._alexa_config.async_initialize()
|
||||||
|
|
||||||
return self._alexa_config
|
return self._alexa_config
|
||||||
|
|
||||||
async def get_google_config(self) -> google_config.CloudGoogleConfig:
|
async def get_google_config(self) -> google_config.CloudGoogleConfig:
|
||||||
"""Return Google config."""
|
"""Return Google config."""
|
||||||
if not self._google_config:
|
if not self._google_config:
|
||||||
assert self.cloud is not None
|
async with self._google_config_init_lock:
|
||||||
|
if self._google_config is not None:
|
||||||
|
return self._google_config
|
||||||
|
|
||||||
cloud_user = await self._prefs.get_cloud_user()
|
assert self.cloud is not None
|
||||||
|
|
||||||
self._google_config = google_config.CloudGoogleConfig(
|
cloud_user = await self._prefs.get_cloud_user()
|
||||||
self._hass, self.google_user_config, cloud_user, self._prefs, self.cloud
|
|
||||||
)
|
self._google_config = google_config.CloudGoogleConfig(
|
||||||
await self._google_config.async_initialize()
|
self._hass,
|
||||||
|
self.google_user_config,
|
||||||
|
cloud_user,
|
||||||
|
self._prefs,
|
||||||
|
self.cloud,
|
||||||
|
)
|
||||||
|
await self._google_config.async_initialize()
|
||||||
|
|
||||||
return self._google_config
|
return self._google_config
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user