Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
SOURCE_STORAGE = "storage"
SOURCE_YAML = "yaml"

# How long to wait till things that run on startup have to finish.
# How long to wait until things that run on startup have to finish.
TIMEOUT_EVENT_START = 15

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -249,7 +249,7 @@ async def async_start(self) -> None:
try:
# Only block for EVENT_HOMEASSISTANT_START listener
self.async_stop_track_tasks()
with timeout(TIMEOUT_EVENT_START):
async with timeout(TIMEOUT_EVENT_START):
await self.async_block_till_done()
except asyncio.TimeoutError:
_LOGGER.warning(
Expand Down Expand Up @@ -374,13 +374,13 @@ def async_run_job(self, target: Callable[..., None], *args: Any) -> None:
self.async_add_job(target, *args)

def block_till_done(self) -> None:
"""Block till all pending work is done."""
"""Block until all pending work is done."""
asyncio.run_coroutine_threadsafe(
self.async_block_till_done(), self.loop
).result()

async def async_block_till_done(self) -> None:
"""Block till all pending work is done."""
"""Block until all pending work is done."""
# To flush out any call_soon_threadsafe
await asyncio.sleep(0)

Expand Down Expand Up @@ -1150,25 +1150,15 @@ def call(
service_data: Optional[Dict] = None,
blocking: bool = False,
context: Optional[Context] = None,
limit: Optional[float] = SERVICE_CALL_LIMIT,
) -> Optional[bool]:
"""
Call a service.

Specify blocking=True to wait till service is executed.
Waits a maximum of SERVICE_CALL_LIMIT.

If blocking = True, will return boolean if service executed
successfully within SERVICE_CALL_LIMIT.

This method will fire an event to call the service.
This event will be picked up by this ServiceRegistry and any
other ServiceRegistry that is listening on the EventBus.

Because the service is sent as an event you are not allowed to use
the keys ATTR_DOMAIN and ATTR_SERVICE in your service_data.
See description of async_call for details.
"""
return asyncio.run_coroutine_threadsafe(
self.async_call(domain, service, service_data, blocking, context),
self.async_call(domain, service, service_data, blocking, context, limit),
self._hass.loop,
).result()

Expand All @@ -1179,19 +1169,18 @@ async def async_call(
service_data: Optional[Dict] = None,
blocking: bool = False,
context: Optional[Context] = None,
limit: Optional[float] = SERVICE_CALL_LIMIT,
) -> Optional[bool]:
"""
Call a service.

Specify blocking=True to wait till service is executed.
Waits a maximum of SERVICE_CALL_LIMIT.
Specify blocking=True to wait until service is executed.
Waits a maximum of limit, which may be None for no timeout.

If blocking = True, will return boolean if service executed
successfully within SERVICE_CALL_LIMIT.
successfully within limit.

This method will fire an event to call the service.
This event will be picked up by this ServiceRegistry and any
other ServiceRegistry that is listening on the EventBus.
This method will fire an event to indicate the service has been called.

Because the service is sent as an event you are not allowed to use
the keys ATTR_DOMAIN and ATTR_SERVICE in your service_data.
Expand Down Expand Up @@ -1230,7 +1219,7 @@ async def async_call(
return None

try:
with timeout(SERVICE_CALL_LIMIT):
async with timeout(limit):
await asyncio.shield(self._execute_service(handler, service_call))
Comment thread
pnbruckner marked this conversation as resolved.
return True
except asyncio.TimeoutError:
Expand Down
Loading