1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

OwnTracks Config Entry (#18759)

* OwnTracks Config Entry

* Fix test

* Fix headers

* Lint

* Username for android only

* Update translations

* Tweak translation

* Create config entry if not there

* Update reqs

* Types

* Lint
This commit is contained in:
Paulus Schoutsen
2018-11-28 22:20:13 +01:00
committed by GitHub
parent e06fa0d2d0
commit 48e28843e6
15 changed files with 554 additions and 355 deletions

View File

@@ -4,7 +4,7 @@ import logging.handlers
from timeit import default_timer as timer
from types import ModuleType
from typing import Optional, Dict, List
from typing import Awaitable, Callable, Optional, Dict, List
from homeassistant import requirements, core, loader, config as conf_util
from homeassistant.config import async_notify_setup_error
@@ -248,3 +248,35 @@ async def async_process_deps_reqs(
raise HomeAssistantError("Could not install all requirements.")
processed.add(name)
@core.callback
def async_when_setup(
hass: core.HomeAssistant, component: str,
when_setup_cb: Callable[
[core.HomeAssistant, str], Awaitable[None]]) -> None:
"""Call a method when a component is setup."""
async def when_setup() -> None:
"""Call the callback."""
try:
await when_setup_cb(hass, component)
except Exception: # pylint: disable=broad-except
_LOGGER.exception('Error handling when_setup callback for %s',
component)
# Running it in a new task so that it always runs after
if component in hass.config.components:
hass.async_create_task(when_setup())
return
unsub = None
async def loaded_event(event: core.Event) -> None:
"""Call the callback."""
if event.data[ATTR_COMPONENT] != component:
return
unsub() # type: ignore
await when_setup()
unsub = hass.bus.async_listen(EVENT_COMPONENT_LOADED, loaded_event)