Add support for after_dependencies (#23148)

* Add support for after_dependencies

* Remove assert false"

* Fix types
This commit is contained in:
Paulus Schoutsen 2019-04-16 13:40:21 -07:00 committed by GitHub
parent 7b1cbeaf80
commit 10e8f4f70a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 296 additions and 60 deletions

View file

@ -21,6 +21,8 @@ from typing import (
TypeVar,
List,
Dict,
Union,
cast,
)
# Typing imports that create a circular dependency
@ -116,6 +118,8 @@ class Integration:
self.name = manifest['name'] # type: str
self.domain = manifest['domain'] # type: str
self.dependencies = manifest['dependencies'] # type: List[str]
self.after_dependencies = manifest.get(
'after_dependencies') # type: Optional[List[str]]
self.requirements = manifest['requirements'] # type: List[str]
_LOGGER.info("Loaded %s from %s", self.domain, pkg_path)
@ -150,7 +154,8 @@ async def async_get_integration(hass: 'HomeAssistant', domain: str)\
raise IntegrationNotFound(domain)
cache = hass.data[DATA_INTEGRATIONS] = {}
int_or_evt = cache.get(domain, _UNDEF) # type: Optional[Integration]
int_or_evt = cache.get(
domain, _UNDEF) # type: Optional[Union[Integration, asyncio.Event]]
if isinstance(int_or_evt, asyncio.Event):
await int_or_evt.wait()
@ -161,7 +166,7 @@ async def async_get_integration(hass: 'HomeAssistant', domain: str)\
elif int_or_evt is None:
raise IntegrationNotFound(domain)
else:
return int_or_evt
return cast(Integration, int_or_evt)
event = cache[domain] = asyncio.Event()