Cleanup coroutine threadsafe (#27080)

* Cleanup coroutine threadsafe

* fix lint

* Fix typing

* Fix tests

* Fix black
This commit is contained in:
Pascal Vizeli 2019-10-01 16:59:06 +02:00 committed by GitHub
parent f4a1f2809b
commit c1851a2d94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 196 additions and 232 deletions

View file

@ -64,11 +64,7 @@ from homeassistant.exceptions import (
Unauthorized,
ServiceNotFound,
)
from homeassistant.util.async_ import (
run_coroutine_threadsafe,
run_callback_threadsafe,
fire_coroutine_threadsafe,
)
from homeassistant.util.async_ import run_callback_threadsafe, fire_coroutine_threadsafe
from homeassistant import util
import homeassistant.util.dt as dt_util
from homeassistant.util import location, slugify
@ -375,7 +371,9 @@ class HomeAssistant:
def block_till_done(self) -> None:
"""Block till all pending work is done."""
run_coroutine_threadsafe(self.async_block_till_done(), self.loop).result()
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."""
@ -1168,7 +1166,7 @@ class ServiceRegistry:
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.
"""
return run_coroutine_threadsafe( # type: ignore
return asyncio.run_coroutine_threadsafe(
self.async_call(domain, service, service_data, blocking, context),
self._hass.loop,
).result()