Cleanup run_callback_threadsafe (#6187)
* Cleanup run_callback_threadsafe * fix spell * Revert image_processing, they need to wait for update
This commit is contained in:
parent
1cd1facbd0
commit
106b7a9d8f
7 changed files with 15 additions and 32 deletions
|
@ -18,7 +18,6 @@ from homeassistant.const import (
|
||||||
SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, ATTR_ENTITY_ID)
|
SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, ATTR_ENTITY_ID)
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers import service, event
|
from homeassistant.helpers import service, event
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -62,8 +61,7 @@ def is_on(hass, entity_id):
|
||||||
|
|
||||||
def turn_on(hass, entity_id):
|
def turn_on(hass, entity_id):
|
||||||
"""Reset the alert."""
|
"""Reset the alert."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_turn_on, hass, entity_id)
|
||||||
hass.loop, async_turn_on, hass, entity_id).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -76,8 +74,7 @@ def async_turn_on(hass, entity_id):
|
||||||
|
|
||||||
def turn_off(hass, entity_id):
|
def turn_off(hass, entity_id):
|
||||||
"""Acknowledge alert."""
|
"""Acknowledge alert."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_turn_off, hass, entity_id)
|
||||||
hass.loop, async_turn_off, hass, entity_id).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -90,7 +87,7 @@ def async_turn_off(hass, entity_id):
|
||||||
|
|
||||||
def toggle(hass, entity_id):
|
def toggle(hass, entity_id):
|
||||||
"""Toggle acknowledgement of alert."""
|
"""Toggle acknowledgement of alert."""
|
||||||
run_callback_threadsafe(hass.loop, async_toggle, hass, entity_id)
|
hass.add_job(async_toggle, hass, entity_id)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -20,8 +20,7 @@ from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.event import async_track_state_change
|
from homeassistant.helpers.event import async_track_state_change
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util.async import (
|
from homeassistant.util.async import run_coroutine_threadsafe
|
||||||
run_callback_threadsafe, run_coroutine_threadsafe)
|
|
||||||
|
|
||||||
DOMAIN = 'group'
|
DOMAIN = 'group'
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ def is_on(hass, entity_id):
|
||||||
|
|
||||||
def reload(hass):
|
def reload(hass):
|
||||||
"""Reload the automation from config."""
|
"""Reload the automation from config."""
|
||||||
hass.services.call(DOMAIN, SERVICE_RELOAD)
|
hass.add_job(async_reload, hass)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -365,7 +364,7 @@ class Group(Entity):
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start tracking members."""
|
"""Start tracking members."""
|
||||||
run_callback_threadsafe(self.hass.loop, self.async_start).result()
|
self.hass.add_job(self.async_start)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_start(self):
|
def async_start(self):
|
||||||
|
|
|
@ -108,8 +108,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
||||||
def process_faces(self, faces, total):
|
def process_faces(self, faces, total):
|
||||||
"""Send event with detected faces and store data."""
|
"""Send event with detected faces and store data."""
|
||||||
run_callback_threadsafe(
|
run_callback_threadsafe(
|
||||||
self.hass.loop, self.async_process_faces, faces, total
|
self.hass.loop, self.async_process_faces, faces, total).result()
|
||||||
).result()
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_process_faces(self, faces, total):
|
def async_process_faces(self, faces, total):
|
||||||
|
|
|
@ -24,8 +24,6 @@ from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.restore_state import async_restore_state
|
from homeassistant.helpers.restore_state import async_restore_state
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
|
||||||
|
|
||||||
|
|
||||||
DOMAIN = "light"
|
DOMAIN = "light"
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
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,
|
rgb_color=None, xy_color=None, color_temp=None, white_value=None,
|
||||||
profile=None, flash=None, effect=None, color_name=None):
|
profile=None, flash=None, effect=None, color_name=None):
|
||||||
"""Turn all or specified light on."""
|
"""Turn all or specified light on."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(
|
||||||
hass.loop, async_turn_on, hass, entity_id, transition, brightness,
|
async_turn_on, hass, entity_id, transition, brightness,
|
||||||
rgb_color, xy_color, color_temp, white_value,
|
rgb_color, xy_color, color_temp, white_value,
|
||||||
profile, flash, effect, color_name).result()
|
profile, flash, effect, color_name)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@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):
|
def turn_off(hass, entity_id=None, transition=None):
|
||||||
"""Turn all or specified light off."""
|
"""Turn all or specified light off."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_turn_off, hass, entity_id, transition)
|
||||||
hass.loop, async_turn_off, hass, entity_id, transition).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -22,7 +22,6 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
||||||
STATE_NOT_HOME, STATE_OFF, STATE_ON,
|
STATE_NOT_HOME, STATE_OFF, STATE_ON,
|
||||||
ATTR_HIDDEN, HTTP_BAD_REQUEST)
|
ATTR_HIDDEN, HTTP_BAD_REQUEST)
|
||||||
from homeassistant.core import State, split_entity_id, DOMAIN as HA_DOMAIN
|
from homeassistant.core import State, split_entity_id, DOMAIN as HA_DOMAIN
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
|
||||||
|
|
||||||
DOMAIN = "logbook"
|
DOMAIN = "logbook"
|
||||||
DEPENDENCIES = ['recorder', 'frontend']
|
DEPENDENCIES = ['recorder', 'frontend']
|
||||||
|
@ -68,9 +67,7 @@ LOG_MESSAGE_SCHEMA = vol.Schema({
|
||||||
|
|
||||||
def log_entry(hass, name, message, domain=None, entity_id=None):
|
def log_entry(hass, name, message, domain=None, entity_id=None):
|
||||||
"""Add an entry to the logbook."""
|
"""Add an entry to the logbook."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_log_entry, hass, name, message, domain, entity_id)
|
||||||
hass.loop, async_log_entry, hass, name, message, domain, entity_id
|
|
||||||
).result()
|
|
||||||
|
|
||||||
|
|
||||||
def async_log_entry(hass, name, message, domain=None, entity_id=None):
|
def async_log_entry(hass, name, message, domain=None, entity_id=None):
|
||||||
|
|
|
@ -16,7 +16,6 @@ from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity import async_generate_entity_id
|
from homeassistant.helpers.entity import async_generate_entity_id
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
|
||||||
|
|
||||||
DOMAIN = 'persistent_notification'
|
DOMAIN = 'persistent_notification'
|
||||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||||
|
@ -39,9 +38,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
def create(hass, message, title=None, notification_id=None):
|
def create(hass, message, title=None, notification_id=None):
|
||||||
"""Generate a notification."""
|
"""Generate a notification."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_create, hass, message, title, notification_id)
|
||||||
hass.loop, async_create, hass, message, title, notification_id
|
|
||||||
).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -21,7 +21,6 @@ from homeassistant.const import (
|
||||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
||||||
ATTR_ENTITY_ID)
|
ATTR_ENTITY_ID)
|
||||||
from homeassistant.components import group
|
from homeassistant.components import group
|
||||||
from homeassistant.util.async import run_callback_threadsafe
|
|
||||||
|
|
||||||
DOMAIN = 'switch'
|
DOMAIN = 'switch'
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
@ -59,8 +58,7 @@ def is_on(hass, entity_id=None):
|
||||||
|
|
||||||
def turn_on(hass, entity_id=None):
|
def turn_on(hass, entity_id=None):
|
||||||
"""Turn all or specified switch on."""
|
"""Turn all or specified switch on."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_turn_on, hass, entity_id)
|
||||||
hass.loop, async_turn_on, hass, entity_id).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -72,8 +70,7 @@ def async_turn_on(hass, entity_id=None):
|
||||||
|
|
||||||
def turn_off(hass, entity_id=None):
|
def turn_off(hass, entity_id=None):
|
||||||
"""Turn all or specified switch off."""
|
"""Turn all or specified switch off."""
|
||||||
run_callback_threadsafe(
|
hass.add_job(async_turn_off, hass, entity_id)
|
||||||
hass.loop, async_turn_off, hass, entity_id).result()
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue