diff --git a/homeassistant/components/alert.py b/homeassistant/components/alert.py index 40c91784a42..24c14e7c9a8 100644 --- a/homeassistant/components/alert.py +++ b/homeassistant/components/alert.py @@ -18,7 +18,6 @@ from homeassistant.const import ( SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, ATTR_ENTITY_ID) from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers import service, event -from homeassistant.util.async import run_callback_threadsafe import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) @@ -62,8 +61,7 @@ def is_on(hass, entity_id): def turn_on(hass, entity_id): """Reset the alert.""" - run_callback_threadsafe( - hass.loop, async_turn_on, hass, entity_id).result() + hass.add_job(async_turn_on, hass, entity_id) @callback @@ -76,8 +74,7 @@ def async_turn_on(hass, entity_id): def turn_off(hass, entity_id): """Acknowledge alert.""" - run_callback_threadsafe( - hass.loop, async_turn_off, hass, entity_id).result() + hass.add_job(async_turn_off, hass, entity_id) @callback @@ -90,7 +87,7 @@ def async_turn_off(hass, entity_id): def toggle(hass, entity_id): """Toggle acknowledgement of alert.""" - run_callback_threadsafe(hass.loop, async_toggle, hass, entity_id) + hass.add_job(async_toggle, hass, entity_id) @callback diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index 230e0e4567f..06e029ffd8c 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -20,8 +20,7 @@ from homeassistant.helpers.entity import Entity, async_generate_entity_id from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.event import async_track_state_change import homeassistant.helpers.config_validation as cv -from homeassistant.util.async import ( - run_callback_threadsafe, run_coroutine_threadsafe) +from homeassistant.util.async import run_coroutine_threadsafe DOMAIN = 'group' @@ -98,7 +97,7 @@ def is_on(hass, entity_id): def reload(hass): """Reload the automation from config.""" - hass.services.call(DOMAIN, SERVICE_RELOAD) + hass.add_job(async_reload, hass) @asyncio.coroutine @@ -365,7 +364,7 @@ class Group(Entity): def start(self): """Start tracking members.""" - run_callback_threadsafe(self.hass.loop, self.async_start).result() + self.hass.add_job(self.async_start) @callback def async_start(self): diff --git a/homeassistant/components/image_processing/microsoft_face_identify.py b/homeassistant/components/image_processing/microsoft_face_identify.py index 8d716bea0d5..97d210d584a 100644 --- a/homeassistant/components/image_processing/microsoft_face_identify.py +++ b/homeassistant/components/image_processing/microsoft_face_identify.py @@ -108,8 +108,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): def process_faces(self, faces, total): """Send event with detected faces and store data.""" run_callback_threadsafe( - self.hass.loop, self.async_process_faces, faces, total - ).result() + self.hass.loop, self.async_process_faces, faces, total).result() @callback def async_process_faces(self, faces, total): diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 05002788207..8b25e2a726b 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -24,8 +24,6 @@ from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa import homeassistant.helpers.config_validation as cv from homeassistant.helpers.restore_state import async_restore_state import homeassistant.util.color as color_util -from homeassistant.util.async import run_callback_threadsafe - DOMAIN = "light" SCAN_INTERVAL = timedelta(seconds=30) @@ -145,10 +143,10 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None, rgb_color=None, xy_color=None, color_temp=None, white_value=None, profile=None, flash=None, effect=None, color_name=None): """Turn all or specified light on.""" - run_callback_threadsafe( - hass.loop, async_turn_on, hass, entity_id, transition, brightness, + hass.add_job( + async_turn_on, hass, entity_id, transition, brightness, rgb_color, xy_color, color_temp, white_value, - profile, flash, effect, color_name).result() + profile, flash, effect, color_name) @callback @@ -178,8 +176,7 @@ def async_turn_on(hass, entity_id=None, transition=None, brightness=None, def turn_off(hass, entity_id=None, transition=None): """Turn all or specified light off.""" - run_callback_threadsafe( - hass.loop, async_turn_off, hass, entity_id, transition).result() + hass.add_job(async_turn_off, hass, entity_id, transition) @callback diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index b69289db989..30d52303099 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -22,7 +22,6 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START, STATE_NOT_HOME, STATE_OFF, STATE_ON, ATTR_HIDDEN, HTTP_BAD_REQUEST) from homeassistant.core import State, split_entity_id, DOMAIN as HA_DOMAIN -from homeassistant.util.async import run_callback_threadsafe DOMAIN = "logbook" DEPENDENCIES = ['recorder', 'frontend'] @@ -68,9 +67,7 @@ LOG_MESSAGE_SCHEMA = vol.Schema({ def log_entry(hass, name, message, domain=None, entity_id=None): """Add an entry to the logbook.""" - run_callback_threadsafe( - hass.loop, async_log_entry, hass, name, message, domain, entity_id - ).result() + hass.add_job(async_log_entry, hass, name, message, domain, entity_id) def async_log_entry(hass, name, message, domain=None, entity_id=None): diff --git a/homeassistant/components/persistent_notification.py b/homeassistant/components/persistent_notification.py index b4dde02baff..d7eef848679 100644 --- a/homeassistant/components/persistent_notification.py +++ b/homeassistant/components/persistent_notification.py @@ -16,7 +16,6 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.util import slugify from homeassistant.config import load_yaml_config_file -from homeassistant.util.async import run_callback_threadsafe DOMAIN = 'persistent_notification' ENTITY_ID_FORMAT = DOMAIN + '.{}' @@ -39,9 +38,7 @@ _LOGGER = logging.getLogger(__name__) def create(hass, message, title=None, notification_id=None): """Generate a notification.""" - run_callback_threadsafe( - hass.loop, async_create, hass, message, title, notification_id - ).result() + hass.add_job(async_create, hass, message, title, notification_id) @callback diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index a5712fcbcbe..01943bc9c69 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -21,7 +21,6 @@ from homeassistant.const import ( STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, ATTR_ENTITY_ID) from homeassistant.components import group -from homeassistant.util.async import run_callback_threadsafe DOMAIN = 'switch' SCAN_INTERVAL = timedelta(seconds=30) @@ -59,8 +58,7 @@ def is_on(hass, entity_id=None): def turn_on(hass, entity_id=None): """Turn all or specified switch on.""" - run_callback_threadsafe( - hass.loop, async_turn_on, hass, entity_id).result() + hass.add_job(async_turn_on, hass, entity_id) @callback @@ -72,8 +70,7 @@ def async_turn_on(hass, entity_id=None): def turn_off(hass, entity_id=None): """Turn all or specified switch off.""" - run_callback_threadsafe( - hass.loop, async_turn_off, hass, entity_id).result() + hass.add_job(async_turn_off, hass, entity_id) @callback