mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Replace executor with async_add_job (#7658)
* Remove executor * Lint * Lint * Fix tests
This commit is contained in:
parent
9e9705d6b2
commit
f43db3c615
@ -83,8 +83,7 @@ def async_from_config_dict(config: Dict[str, Any],
|
|||||||
conf_util.async_log_exception(ex, 'homeassistant', core_config, hass)
|
conf_util.async_log_exception(ex, 'homeassistant', core_config, hass)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(conf_util.process_ha_config_upgrade, hass)
|
||||||
None, conf_util.process_ha_config_upgrade, hass)
|
|
||||||
|
|
||||||
if enable_log:
|
if enable_log:
|
||||||
async_enable_logging(hass, verbose, log_rotate_days)
|
async_enable_logging(hass, verbose, log_rotate_days)
|
||||||
@ -95,7 +94,7 @@ def async_from_config_dict(config: Dict[str, Any],
|
|||||||
'This may cause issues.')
|
'This may cause issues.')
|
||||||
|
|
||||||
if not loader.PREPARED:
|
if not loader.PREPARED:
|
||||||
yield from hass.loop.run_in_executor(None, loader.prepare, hass)
|
yield from hass.async_add_job(loader.prepare, hass)
|
||||||
|
|
||||||
# Merge packages
|
# Merge packages
|
||||||
conf_util.merge_packages_config(
|
conf_util.merge_packages_config(
|
||||||
@ -184,14 +183,13 @@ def async_from_config_file(config_path: str,
|
|||||||
# Set config dir to directory holding config file
|
# Set config dir to directory holding config file
|
||||||
config_dir = os.path.abspath(os.path.dirname(config_path))
|
config_dir = os.path.abspath(os.path.dirname(config_path))
|
||||||
hass.config.config_dir = config_dir
|
hass.config.config_dir = config_dir
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(mount_local_lib_path, config_dir)
|
||||||
None, mount_local_lib_path, config_dir)
|
|
||||||
|
|
||||||
async_enable_logging(hass, verbose, log_rotate_days)
|
async_enable_logging(hass, verbose, log_rotate_days)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config_dict = yield from hass.loop.run_in_executor(
|
config_dict = yield from hass.async_add_job(
|
||||||
None, conf_util.load_yaml_config_file, config_path)
|
conf_util.load_yaml_config_file, config_path)
|
||||||
except HomeAssistantError as err:
|
except HomeAssistantError as err:
|
||||||
_LOGGER.error('Error loading %s: %s', config_path, err)
|
_LOGGER.error('Error loading %s: %s', config_path, err)
|
||||||
return None
|
return None
|
||||||
|
@ -123,8 +123,8 @@ def async_setup(hass, config):
|
|||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
for service in SERVICE_TO_METHOD:
|
for service in SERVICE_TO_METHOD:
|
||||||
@ -158,8 +158,7 @@ class AlarmControlPanel(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.alarm_disarm, code)
|
||||||
None, self.alarm_disarm, code)
|
|
||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
def alarm_arm_home(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
@ -170,8 +169,7 @@ class AlarmControlPanel(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.alarm_arm_home, code)
|
||||||
None, self.alarm_arm_home, code)
|
|
||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
def alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
@ -182,8 +180,7 @@ class AlarmControlPanel(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.alarm_arm_away, code)
|
||||||
None, self.alarm_arm_away, code)
|
|
||||||
|
|
||||||
def alarm_trigger(self, code=None):
|
def alarm_trigger(self, code=None):
|
||||||
"""Send alarm trigger command."""
|
"""Send alarm trigger command."""
|
||||||
@ -194,8 +191,7 @@ class AlarmControlPanel(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.alarm_trigger, code)
|
||||||
None, self.alarm_trigger, code)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
|
@ -70,8 +70,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
device.async_alarm_keypress(keypress)
|
device.async_alarm_keypress(keypress)
|
||||||
|
|
||||||
# Register Envisalink specific services
|
# Register Envisalink specific services
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
|
@ -128,8 +128,8 @@ def async_setup(hass, config):
|
|||||||
all_alerts[entity.entity_id] = entity
|
all_alerts[entity.entity_id] = entity
|
||||||
|
|
||||||
# Read descriptions
|
# Read descriptions
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
descriptions = descriptions.get(DOMAIN, {})
|
descriptions = descriptions.get(DOMAIN, {})
|
||||||
|
|
||||||
|
@ -158,8 +158,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
yield from _async_process_config(hass, config, component)
|
yield from _async_process_config(hass, config, component)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, conf_util.load_yaml_config_file, os.path.join(
|
conf_util.load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml')
|
os.path.dirname(__file__), 'services.yaml')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class Camera(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(None, self.camera_image)
|
return self.hass.async_add_job(self.camera_image)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def handle_async_mjpeg_stream(self, request):
|
def handle_async_mjpeg_stream(self, request):
|
||||||
|
@ -103,8 +103,8 @@ class GenericCamera(Camera):
|
|||||||
_LOGGER.error("Error getting camera image: %s", error)
|
_LOGGER.error("Error getting camera image: %s", error)
|
||||||
return self._last_image
|
return self._last_image
|
||||||
|
|
||||||
self._last_image = yield from self.hass.loop.run_in_executor(
|
self._last_image = yield from self.hass.async_add_job(
|
||||||
None, fetch)
|
fetch)
|
||||||
# async
|
# async
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -88,8 +88,8 @@ class MjpegCamera(Camera):
|
|||||||
# DigestAuth is not supported
|
# DigestAuth is not supported
|
||||||
if self._authentication == HTTP_DIGEST_AUTHENTICATION or \
|
if self._authentication == HTTP_DIGEST_AUTHENTICATION or \
|
||||||
self._still_image_url is None:
|
self._still_image_url is None:
|
||||||
image = yield from self.hass.loop.run_in_executor(
|
image = yield from self.hass.async_add_job(
|
||||||
None, self.camera_image)
|
self.camera_image)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
websession = async_get_clientsession(self.hass)
|
websession = async_get_clientsession(self.hass)
|
||||||
|
@ -213,8 +213,8 @@ def async_setup(hass, config):
|
|||||||
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
||||||
yield from component.async_setup(config)
|
yield from component.async_setup(config)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -569,8 +569,8 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.set_temperature, **kwargs))
|
ft.partial(self.set_temperature, **kwargs))
|
||||||
|
|
||||||
def set_humidity(self, humidity):
|
def set_humidity(self, humidity):
|
||||||
"""Set new target humidity."""
|
"""Set new target humidity."""
|
||||||
@ -581,8 +581,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_humidity, humidity)
|
||||||
None, self.set_humidity, humidity)
|
|
||||||
|
|
||||||
def set_fan_mode(self, fan):
|
def set_fan_mode(self, fan):
|
||||||
"""Set new target fan mode."""
|
"""Set new target fan mode."""
|
||||||
@ -593,8 +592,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_fan_mode, fan)
|
||||||
None, self.set_fan_mode, fan)
|
|
||||||
|
|
||||||
def set_operation_mode(self, operation_mode):
|
def set_operation_mode(self, operation_mode):
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
@ -605,8 +603,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_operation_mode, operation_mode)
|
||||||
None, self.set_operation_mode, operation_mode)
|
|
||||||
|
|
||||||
def set_swing_mode(self, swing_mode):
|
def set_swing_mode(self, swing_mode):
|
||||||
"""Set new target swing operation."""
|
"""Set new target swing operation."""
|
||||||
@ -617,8 +614,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_swing_mode, swing_mode)
|
||||||
None, self.set_swing_mode, swing_mode)
|
|
||||||
|
|
||||||
def turn_away_mode_on(self):
|
def turn_away_mode_on(self):
|
||||||
"""Turn away mode on."""
|
"""Turn away mode on."""
|
||||||
@ -629,8 +625,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_away_mode_on)
|
||||||
None, self.turn_away_mode_on)
|
|
||||||
|
|
||||||
def turn_away_mode_off(self):
|
def turn_away_mode_off(self):
|
||||||
"""Turn away mode off."""
|
"""Turn away mode off."""
|
||||||
@ -641,8 +636,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_away_mode_off)
|
||||||
None, self.turn_away_mode_off)
|
|
||||||
|
|
||||||
def set_hold_mode(self, hold_mode):
|
def set_hold_mode(self, hold_mode):
|
||||||
"""Set new target hold mode."""
|
"""Set new target hold mode."""
|
||||||
@ -653,8 +647,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_hold_mode, hold_mode)
|
||||||
None, self.set_hold_mode, hold_mode)
|
|
||||||
|
|
||||||
def turn_aux_heat_on(self):
|
def turn_aux_heat_on(self):
|
||||||
"""Turn auxillary heater on."""
|
"""Turn auxillary heater on."""
|
||||||
@ -665,8 +658,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_aux_heat_on)
|
||||||
None, self.turn_aux_heat_on)
|
|
||||||
|
|
||||||
def turn_aux_heat_off(self):
|
def turn_aux_heat_off(self):
|
||||||
"""Turn auxillary heater off."""
|
"""Turn auxillary heater off."""
|
||||||
@ -677,8 +669,7 @@ class ClimateDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_aux_heat_off)
|
||||||
None, self.turn_aux_heat_off)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def min_temp(self):
|
||||||
|
@ -175,8 +175,8 @@ def async_setup(hass, config):
|
|||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
for service_name in SERVICE_TO_METHOD:
|
for service_name in SERVICE_TO_METHOD:
|
||||||
@ -263,8 +263,7 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.open_cover, **kwargs))
|
||||||
None, ft.partial(self.open_cover, **kwargs))
|
|
||||||
|
|
||||||
def close_cover(self, **kwargs):
|
def close_cover(self, **kwargs):
|
||||||
"""Close cover."""
|
"""Close cover."""
|
||||||
@ -275,8 +274,7 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.close_cover, **kwargs))
|
||||||
None, ft.partial(self.close_cover, **kwargs))
|
|
||||||
|
|
||||||
def set_cover_position(self, **kwargs):
|
def set_cover_position(self, **kwargs):
|
||||||
"""Move the cover to a specific position."""
|
"""Move the cover to a specific position."""
|
||||||
@ -287,8 +285,8 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.set_cover_position, **kwargs))
|
ft.partial(self.set_cover_position, **kwargs))
|
||||||
|
|
||||||
def stop_cover(self, **kwargs):
|
def stop_cover(self, **kwargs):
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
@ -299,8 +297,7 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.stop_cover, **kwargs))
|
||||||
None, ft.partial(self.stop_cover, **kwargs))
|
|
||||||
|
|
||||||
def open_cover_tilt(self, **kwargs):
|
def open_cover_tilt(self, **kwargs):
|
||||||
"""Open the cover tilt."""
|
"""Open the cover tilt."""
|
||||||
@ -311,8 +308,8 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.open_cover_tilt, **kwargs))
|
ft.partial(self.open_cover_tilt, **kwargs))
|
||||||
|
|
||||||
def close_cover_tilt(self, **kwargs):
|
def close_cover_tilt(self, **kwargs):
|
||||||
"""Close the cover tilt."""
|
"""Close the cover tilt."""
|
||||||
@ -323,8 +320,8 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.close_cover_tilt, **kwargs))
|
ft.partial(self.close_cover_tilt, **kwargs))
|
||||||
|
|
||||||
def set_cover_tilt_position(self, **kwargs):
|
def set_cover_tilt_position(self, **kwargs):
|
||||||
"""Move the cover tilt to a specific position."""
|
"""Move the cover tilt to a specific position."""
|
||||||
@ -335,8 +332,8 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.set_cover_tilt_position, **kwargs))
|
ft.partial(self.set_cover_tilt_position, **kwargs))
|
||||||
|
|
||||||
def stop_cover_tilt(self, **kwargs):
|
def stop_cover_tilt(self, **kwargs):
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
@ -347,5 +344,5 @@ class CoverDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.stop_cover_tilt, **kwargs))
|
ft.partial(self.stop_cover_tilt, **kwargs))
|
||||||
|
@ -75,10 +75,10 @@ class GPSLoggerView(HomeAssistantView):
|
|||||||
if 'activity' in data:
|
if 'activity' in data:
|
||||||
attrs['activity'] = data['activity']
|
attrs['activity'] = data['activity']
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, partial(self.see, dev_id=device,
|
partial(self.see, dev_id=device,
|
||||||
gps=gps_location, battery=battery,
|
gps=gps_location, battery=battery,
|
||||||
gps_accuracy=accuracy,
|
gps_accuracy=accuracy,
|
||||||
attributes=attrs))
|
attributes=attrs))
|
||||||
|
|
||||||
return 'Setting location for {}'.format(device)
|
return 'Setting location for {}'.format(device)
|
||||||
|
@ -79,10 +79,9 @@ class LocativeView(HomeAssistantView):
|
|||||||
gps_location = (data[ATTR_LATITUDE], data[ATTR_LONGITUDE])
|
gps_location = (data[ATTR_LATITUDE], data[ATTR_LONGITUDE])
|
||||||
|
|
||||||
if direction == 'enter':
|
if direction == 'enter':
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, partial(self.see, dev_id=device,
|
partial(self.see, dev_id=device, location_name=location_name,
|
||||||
location_name=location_name,
|
gps=gps_location))
|
||||||
gps=gps_location))
|
|
||||||
return 'Setting location to {}'.format(location_name)
|
return 'Setting location to {}'.format(location_name)
|
||||||
|
|
||||||
elif direction == 'exit':
|
elif direction == 'exit':
|
||||||
@ -91,10 +90,9 @@ class LocativeView(HomeAssistantView):
|
|||||||
|
|
||||||
if current_state is None or current_state.state == location_name:
|
if current_state is None or current_state.state == location_name:
|
||||||
location_name = STATE_NOT_HOME
|
location_name = STATE_NOT_HOME
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, partial(self.see, dev_id=device,
|
partial(self.see, dev_id=device,
|
||||||
location_name=location_name,
|
location_name=location_name, gps=gps_location))
|
||||||
gps=gps_location))
|
|
||||||
return 'Setting location to not home'
|
return 'Setting location to not home'
|
||||||
else:
|
else:
|
||||||
# Ignore the message if it is telling us to exit a zone that we
|
# Ignore the message if it is telling us to exit a zone that we
|
||||||
|
@ -115,8 +115,7 @@ def async_setup(hass, config):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def scan_devices(now):
|
def scan_devices(now):
|
||||||
"""Scan for devices."""
|
"""Scan for devices."""
|
||||||
results = yield from hass.loop.run_in_executor(
|
results = yield from hass.async_add_job(_discover, netdisco)
|
||||||
None, _discover, netdisco)
|
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
hass.async_add_job(new_service_found(*result))
|
hass.async_add_job(new_service_found(*result))
|
||||||
|
@ -159,8 +159,8 @@ def async_setup(hass, config):
|
|||||||
CONF_BINARY_SENSORS: binary_sensors,
|
CONF_BINARY_SENSORS: binary_sensors,
|
||||||
}, config))
|
}, config))
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -229,8 +229,8 @@ def async_setup(hass, config: dict):
|
|||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
# Listen for fan service calls.
|
# Listen for fan service calls.
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
for service_name in SERVICE_TO_METHOD:
|
for service_name in SERVICE_TO_METHOD:
|
||||||
@ -256,7 +256,7 @@ class FanEntity(ToggleEntity):
|
|||||||
"""
|
"""
|
||||||
if speed is SPEED_OFF:
|
if speed is SPEED_OFF:
|
||||||
return self.async_turn_off()
|
return self.async_turn_off()
|
||||||
return self.hass.loop.run_in_executor(None, self.set_speed, speed)
|
return self.hass.async_add_job(self.set_speed, speed)
|
||||||
|
|
||||||
def set_direction(self: ToggleEntity, direction: str) -> None:
|
def set_direction(self: ToggleEntity, direction: str) -> None:
|
||||||
"""Set the direction of the fan."""
|
"""Set the direction of the fan."""
|
||||||
@ -267,8 +267,7 @@ class FanEntity(ToggleEntity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_direction, direction)
|
||||||
None, self.set_direction, direction)
|
|
||||||
|
|
||||||
def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None:
|
def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None:
|
||||||
"""Turn on the fan."""
|
"""Turn on the fan."""
|
||||||
@ -281,8 +280,8 @@ class FanEntity(ToggleEntity):
|
|||||||
"""
|
"""
|
||||||
if speed is SPEED_OFF:
|
if speed is SPEED_OFF:
|
||||||
return self.async_turn_off()
|
return self.async_turn_off()
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.turn_on, speed, **kwargs))
|
ft.partial(self.turn_on, speed, **kwargs))
|
||||||
|
|
||||||
def oscillate(self: ToggleEntity, oscillating: bool) -> None:
|
def oscillate(self: ToggleEntity, oscillating: bool) -> None:
|
||||||
"""Oscillate the fan."""
|
"""Oscillate the fan."""
|
||||||
@ -293,8 +292,7 @@ class FanEntity(ToggleEntity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.oscillate, oscillating)
|
||||||
None, self.oscillate, oscillating)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
@ -89,8 +89,8 @@ def async_setup(hass, config):
|
|||||||
conf.get(CONF_RUN_TEST, DEFAULT_RUN_TEST)
|
conf.get(CONF_RUN_TEST, DEFAULT_RUN_TEST)
|
||||||
)
|
)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
# Register service
|
# Register service
|
||||||
|
@ -268,8 +268,8 @@ class IndexView(HomeAssistantView):
|
|||||||
no_auth = 'true'
|
no_auth = 'true'
|
||||||
|
|
||||||
icons_url = '/static/mdi-{}.html'.format(FINGERPRINTS['mdi.html'])
|
icons_url = '/static/mdi-{}.html'.format(FINGERPRINTS['mdi.html'])
|
||||||
template = yield from hass.loop.run_in_executor(
|
template = yield from hass.async_add_job(
|
||||||
None, self.templates.get_template, 'index.html')
|
self.templates.get_template, 'index.html')
|
||||||
|
|
||||||
# pylint is wrong
|
# pylint is wrong
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
|
@ -173,8 +173,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
yield from _async_process_config(hass, config, component)
|
yield from _async_process_config(hass, config, component)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, conf_util.load_yaml_config_file, os.path.join(
|
conf_util.load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml')
|
os.path.dirname(__file__), 'services.yaml')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -233,9 +233,9 @@ class HistoryPeriodView(HomeAssistantView):
|
|||||||
end_time = start_time + one_day
|
end_time = start_time + one_day
|
||||||
entity_id = request.GET.get('filter_entity_id')
|
entity_id = request.GET.get('filter_entity_id')
|
||||||
|
|
||||||
result = yield from request.app['hass'].loop.run_in_executor(
|
result = yield from request.app['hass'].async_add_job(
|
||||||
None, get_significant_states, request.app['hass'], start_time,
|
get_significant_states, request.app['hass'], start_time, end_time,
|
||||||
end_time, entity_id, self.filters)
|
entity_id, self.filters)
|
||||||
result = result.values()
|
result = result.values()
|
||||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
elapsed = time.perf_counter() - timer_start
|
elapsed = time.perf_counter() - timer_start
|
||||||
|
@ -40,8 +40,8 @@ def ban_middleware(app, handler):
|
|||||||
|
|
||||||
if KEY_BANNED_IPS not in app:
|
if KEY_BANNED_IPS not in app:
|
||||||
hass = app['hass']
|
hass = app['hass']
|
||||||
app[KEY_BANNED_IPS] = yield from hass.loop.run_in_executor(
|
app[KEY_BANNED_IPS] = yield from hass.async_add_job(
|
||||||
None, load_ip_bans_config, hass.config.path(IP_BANS_FILE))
|
load_ip_bans_config, hass.config.path(IP_BANS_FILE))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def ban_middleware_handler(request):
|
def ban_middleware_handler(request):
|
||||||
@ -90,9 +90,8 @@ def process_wrong_login(request):
|
|||||||
request.app[KEY_BANNED_IPS].append(new_ban)
|
request.app[KEY_BANNED_IPS].append(new_ban)
|
||||||
|
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, update_ip_bans_config, hass.config.path(IP_BANS_FILE),
|
update_ip_bans_config, hass.config.path(IP_BANS_FILE), new_ban)
|
||||||
new_ban)
|
|
||||||
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Banned IP %s for too many login attempts", remote_addr)
|
"Banned IP %s for too many login attempts", remote_addr)
|
||||||
|
@ -72,8 +72,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
yield from component.async_setup(config)
|
yield from component.async_setup(config)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -117,7 +117,7 @@ class ImageProcessingEntity(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(None, self.process_image, image)
|
return self.hass.async_add_job(self.process_image, image)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_update(self):
|
def async_update(self):
|
||||||
|
@ -285,8 +285,8 @@ def async_setup(hass, config):
|
|||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
# Listen for light on and light off service calls.
|
# Listen for light on and light off service calls.
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
@ -341,8 +341,7 @@ class Profiles:
|
|||||||
return None
|
return None
|
||||||
return profiles
|
return profiles
|
||||||
|
|
||||||
cls._all = yield from hass.loop.run_in_executor(
|
cls._all = yield from hass.async_add_job(load_profile_data, hass)
|
||||||
None, load_profile_data, hass)
|
|
||||||
return cls._all is not None
|
return cls._all is not None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -108,8 +108,8 @@ def async_setup(hass, config):
|
|||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
@ -150,8 +150,7 @@ class LockDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.lock, **kwargs))
|
||||||
None, ft.partial(self.lock, **kwargs))
|
|
||||||
|
|
||||||
def unlock(self, **kwargs):
|
def unlock(self, **kwargs):
|
||||||
"""Unlock the lock."""
|
"""Unlock the lock."""
|
||||||
@ -162,8 +161,7 @@ class LockDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.unlock, **kwargs))
|
||||||
None, ft.partial(self.unlock, **kwargs))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
|
@ -134,8 +134,8 @@ class LogbookView(HomeAssistantView):
|
|||||||
end_day = start_day + timedelta(days=1)
|
end_day = start_day + timedelta(days=1)
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
|
|
||||||
events = yield from hass.loop.run_in_executor(
|
events = yield from hass.async_add_job(
|
||||||
None, _get_events, hass, start_day, end_day)
|
_get_events, hass, start_day, end_day)
|
||||||
events = _exclude_events(events, self.config)
|
events = _exclude_events(events, self.config)
|
||||||
return self.json(humanify(events))
|
return self.json(humanify(events))
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ def async_setup(hass, config):
|
|||||||
"""Handle logger services."""
|
"""Handle logger services."""
|
||||||
set_log_levels(service.data)
|
set_log_levels(service.data)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
|
@ -353,8 +353,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
yield from component.async_setup(config)
|
yield from component.async_setup(config)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -583,8 +583,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_on)
|
||||||
None, self.turn_on)
|
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn the media player off."""
|
"""Turn the media player off."""
|
||||||
@ -595,8 +594,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.turn_off)
|
||||||
None, self.turn_off)
|
|
||||||
|
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
"""Mute the volume."""
|
"""Mute the volume."""
|
||||||
@ -607,8 +605,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.mute_volume, mute)
|
||||||
None, self.mute_volume, mute)
|
|
||||||
|
|
||||||
def set_volume_level(self, volume):
|
def set_volume_level(self, volume):
|
||||||
"""Set volume level, range 0..1."""
|
"""Set volume level, range 0..1."""
|
||||||
@ -619,8 +616,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_volume_level, volume)
|
||||||
None, self.set_volume_level, volume)
|
|
||||||
|
|
||||||
def media_play(self):
|
def media_play(self):
|
||||||
"""Send play commmand."""
|
"""Send play commmand."""
|
||||||
@ -631,8 +627,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_play)
|
||||||
None, self.media_play)
|
|
||||||
|
|
||||||
def media_pause(self):
|
def media_pause(self):
|
||||||
"""Send pause command."""
|
"""Send pause command."""
|
||||||
@ -643,8 +638,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_pause)
|
||||||
None, self.media_pause)
|
|
||||||
|
|
||||||
def media_stop(self):
|
def media_stop(self):
|
||||||
"""Send stop command."""
|
"""Send stop command."""
|
||||||
@ -655,8 +649,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_stop)
|
||||||
None, self.media_stop)
|
|
||||||
|
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Send previous track command."""
|
"""Send previous track command."""
|
||||||
@ -667,8 +660,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_previous_track)
|
||||||
None, self.media_previous_track)
|
|
||||||
|
|
||||||
def media_next_track(self):
|
def media_next_track(self):
|
||||||
"""Send next track command."""
|
"""Send next track command."""
|
||||||
@ -679,8 +671,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_next_track)
|
||||||
None, self.media_next_track)
|
|
||||||
|
|
||||||
def media_seek(self, position):
|
def media_seek(self, position):
|
||||||
"""Send seek command."""
|
"""Send seek command."""
|
||||||
@ -691,8 +682,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.media_seek, position)
|
||||||
None, self.media_seek, position)
|
|
||||||
|
|
||||||
def play_media(self, media_type, media_id, **kwargs):
|
def play_media(self, media_type, media_id, **kwargs):
|
||||||
"""Play a piece of media."""
|
"""Play a piece of media."""
|
||||||
@ -703,8 +693,8 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.play_media, media_type, media_id, **kwargs))
|
ft.partial(self.play_media, media_type, media_id, **kwargs))
|
||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Select input source."""
|
"""Select input source."""
|
||||||
@ -715,8 +705,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.select_source, source)
|
||||||
None, self.select_source, source)
|
|
||||||
|
|
||||||
def clear_playlist(self):
|
def clear_playlist(self):
|
||||||
"""Clear players playlist."""
|
"""Clear players playlist."""
|
||||||
@ -727,8 +716,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.clear_playlist)
|
||||||
None, self.clear_playlist)
|
|
||||||
|
|
||||||
def set_shuffle(self, shuffle):
|
def set_shuffle(self, shuffle):
|
||||||
"""Enable/disable shuffle mode."""
|
"""Enable/disable shuffle mode."""
|
||||||
@ -739,8 +727,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(self.set_shuffle, shuffle)
|
||||||
None, self.set_shuffle, shuffle)
|
|
||||||
|
|
||||||
# No need to overwrite these.
|
# No need to overwrite these.
|
||||||
@property
|
@property
|
||||||
@ -810,7 +797,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
"""
|
"""
|
||||||
if hasattr(self, 'toggle'):
|
if hasattr(self, 'toggle'):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
return self.hass.loop.run_in_executor(None, self.toggle)
|
return self.hass.async_add_job(self.toggle)
|
||||||
|
|
||||||
if self.state in [STATE_OFF, STATE_IDLE]:
|
if self.state in [STATE_OFF, STATE_IDLE]:
|
||||||
return self.async_turn_on()
|
return self.async_turn_on()
|
||||||
@ -825,7 +812,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
"""
|
"""
|
||||||
if hasattr(self, 'volume_up'):
|
if hasattr(self, 'volume_up'):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
yield from self.hass.loop.run_in_executor(None, self.volume_up)
|
yield from self.hass.async_add_job(self.volume_up)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.volume_level < 1:
|
if self.volume_level < 1:
|
||||||
@ -840,7 +827,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
"""
|
"""
|
||||||
if hasattr(self, 'volume_down'):
|
if hasattr(self, 'volume_down'):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
yield from self.hass.loop.run_in_executor(None, self.volume_down)
|
yield from self.hass.async_add_job(self.volume_down)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.volume_level > 0:
|
if self.volume_level > 0:
|
||||||
@ -854,7 +841,7 @@ class MediaPlayerDevice(Entity):
|
|||||||
"""
|
"""
|
||||||
if hasattr(self, 'media_play_pause'):
|
if hasattr(self, 'media_play_pause'):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
return self.hass.loop.run_in_executor(None, self.media_play_pause)
|
return self.hass.async_add_job(self.media_play_pause)
|
||||||
|
|
||||||
if self.state == STATE_PLAYING:
|
if self.state == STATE_PLAYING:
|
||||||
return self.async_media_pause()
|
return self.async_media_pause()
|
||||||
|
@ -175,8 +175,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
if hass.services.has_service(DOMAIN, SERVICE_ADD_MEDIA):
|
if hass.services.has_service(DOMAIN, SERVICE_ADD_MEDIA):
|
||||||
return
|
return
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
for service in SERVICE_TO_METHOD:
|
for service in SERVICE_TO_METHOD:
|
||||||
|
@ -133,8 +133,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
hass.data[DATA_MICROSOFT_FACE] = face
|
hass.data[DATA_MICROSOFT_FACE] = face
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -403,8 +403,8 @@ def async_setup(hass, config):
|
|||||||
yield from hass.data[DATA_MQTT].async_publish(
|
yield from hass.data[DATA_MQTT].async_publish(
|
||||||
msg_topic, payload, qos, retain)
|
msg_topic, payload, qos, retain)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
@ -477,8 +477,8 @@ class MQTT(object):
|
|||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
with (yield from self._paho_lock):
|
with (yield from self._paho_lock):
|
||||||
yield from self.hass.loop.run_in_executor(
|
yield from self.hass.async_add_job(
|
||||||
None, self._mqttc.publish, topic, payload, qos, retain)
|
self._mqttc.publish, topic, payload, qos, retain)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_connect(self):
|
def async_connect(self):
|
||||||
@ -486,8 +486,8 @@ class MQTT(object):
|
|||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
result = yield from self.hass.loop.run_in_executor(
|
result = yield from self.hass.async_add_job(
|
||||||
None, self._mqttc.connect, self.broker, self.port, self.keepalive)
|
self._mqttc.connect, self.broker, self.port, self.keepalive)
|
||||||
|
|
||||||
if result != 0:
|
if result != 0:
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
@ -507,7 +507,7 @@ class MQTT(object):
|
|||||||
self._mqttc.disconnect()
|
self._mqttc.disconnect()
|
||||||
self._mqttc.loop_stop()
|
self._mqttc.loop_stop()
|
||||||
|
|
||||||
return self.hass.loop.run_in_executor(None, stop)
|
return self.hass.async_add_job(stop)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_subscribe(self, topic, qos):
|
def async_subscribe(self, topic, qos):
|
||||||
@ -522,8 +522,8 @@ class MQTT(object):
|
|||||||
if topic in self.topics:
|
if topic in self.topics:
|
||||||
return
|
return
|
||||||
|
|
||||||
result, mid = yield from self.hass.loop.run_in_executor(
|
result, mid = yield from self.hass.async_add_job(
|
||||||
None, self._mqttc.subscribe, topic, qos)
|
self._mqttc.subscribe, topic, qos)
|
||||||
|
|
||||||
_raise_on_error(result)
|
_raise_on_error(result)
|
||||||
self.progress[mid] = topic
|
self.progress[mid] = topic
|
||||||
@ -535,8 +535,8 @@ class MQTT(object):
|
|||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
result, mid = yield from self.hass.loop.run_in_executor(
|
result, mid = yield from self.hass.async_add_job(
|
||||||
None, self._mqttc.unsubscribe, topic)
|
self._mqttc.unsubscribe, topic)
|
||||||
|
|
||||||
_raise_on_error(result)
|
_raise_on_error(result)
|
||||||
self.progress[mid] = topic
|
self.progress[mid] = topic
|
||||||
|
@ -69,8 +69,8 @@ def send_message(hass, message, title=None, data=None):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Set up the notify services."""
|
"""Set up the notify services."""
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
targets = {}
|
targets = {}
|
||||||
@ -97,8 +97,8 @@ def async_setup(hass, config):
|
|||||||
notify_service = yield from \
|
notify_service = yield from \
|
||||||
platform.async_get_service(hass, p_config, discovery_info)
|
platform.async_get_service(hass, p_config, discovery_info)
|
||||||
elif hasattr(platform, 'get_service'):
|
elif hasattr(platform, 'get_service'):
|
||||||
notify_service = yield from hass.loop.run_in_executor(
|
notify_service = yield from hass.async_add_job(
|
||||||
None, platform.get_service, hass, p_config, discovery_info)
|
platform.get_service, hass, p_config, discovery_info)
|
||||||
else:
|
else:
|
||||||
raise HomeAssistantError("Invalid notify platform.")
|
raise HomeAssistantError("Invalid notify platform.")
|
||||||
|
|
||||||
@ -192,5 +192,5 @@ class BaseNotificationService(object):
|
|||||||
kwargs can contain ATTR_TITLE to specify a title.
|
kwargs can contain ATTR_TITLE to specify a title.
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, partial(self.send_message, message, **kwargs))
|
partial(self.send_message, message, **kwargs))
|
||||||
|
@ -92,8 +92,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
hass.states.async_set(entity_id, message, attr)
|
hass.states.async_set(entity_id, message, attr)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml')
|
os.path.dirname(__file__), 'services.yaml')
|
||||||
)
|
)
|
||||||
hass.services.async_register(DOMAIN, SERVICE_CREATE, create_service,
|
hass.services.async_register(DOMAIN, SERVICE_CREATE, create_service,
|
||||||
|
@ -140,8 +140,8 @@ def async_setup(hass, config):
|
|||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_TURN_OFF, async_handle_remote_service,
|
DOMAIN, SERVICE_TURN_OFF, async_handle_remote_service,
|
||||||
@ -171,5 +171,4 @@ class RemoteDevice(ToggleEntity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.send_command, **kwargs))
|
||||||
None, ft.partial(self.send_command, **kwargs))
|
|
||||||
|
@ -75,5 +75,4 @@ class KiraRemote(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(ft.partial(self.send_command, **kwargs))
|
||||||
None, ft.partial(self.send_command, **kwargs))
|
|
||||||
|
@ -371,7 +371,7 @@ class RflinkCommand(RflinkDevice):
|
|||||||
# Rflink protocol/transport handles asynchronous writing of buffer
|
# Rflink protocol/transport handles asynchronous writing of buffer
|
||||||
# to serial/tcp device. Does not wait for command send
|
# to serial/tcp device. Does not wait for command send
|
||||||
# confirmation.
|
# confirmation.
|
||||||
self.hass.loop.run_in_executor(None, ft.partial(
|
self.hass.async_add_job(ft.partial(
|
||||||
self._protocol.send_command, self._device_id, cmd))
|
self._protocol.send_command, self._device_id, cmd))
|
||||||
|
|
||||||
if repetitions > 1:
|
if repetitions > 1:
|
||||||
|
@ -112,4 +112,4 @@ class Scene(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(None, self.activate)
|
return self.hass.async_add_job(self.activate)
|
||||||
|
@ -122,8 +122,8 @@ def async_setup(hass, config):
|
|||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file, os.path.join(
|
load_yaml_config_file, os.path.join(
|
||||||
os.path.dirname(__file__), 'services.yaml'))
|
os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
|
@ -72,8 +72,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _learn_command(call):
|
def _learn_command(call):
|
||||||
try:
|
try:
|
||||||
auth = yield from hass.loop.run_in_executor(None,
|
auth = yield from hass.async_add_job(broadlink_device.auth)
|
||||||
broadlink_device.auth)
|
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
_LOGGER.error("Failed to connect to device, timeout")
|
_LOGGER.error("Failed to connect to device, timeout")
|
||||||
return
|
return
|
||||||
@ -81,14 +80,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
_LOGGER.error("Failed to connect to device")
|
_LOGGER.error("Failed to connect to device")
|
||||||
return
|
return
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(broadlink_device.enter_learning)
|
||||||
None, broadlink_device.enter_learning)
|
|
||||||
|
|
||||||
_LOGGER.info("Press the key you want HASS to learn")
|
_LOGGER.info("Press the key you want HASS to learn")
|
||||||
start_time = utcnow()
|
start_time = utcnow()
|
||||||
while (utcnow() - start_time) < timedelta(seconds=20):
|
while (utcnow() - start_time) < timedelta(seconds=20):
|
||||||
packet = yield from hass.loop.run_in_executor(
|
packet = yield from hass.async_add_job(
|
||||||
None, broadlink_device.check_data)
|
broadlink_device.check_data)
|
||||||
if packet:
|
if packet:
|
||||||
log_msg = "Recieved packet is: {}".\
|
log_msg = "Recieved packet is: {}".\
|
||||||
format(b64encode(packet).decode('utf8'))
|
format(b64encode(packet).decode('utf8'))
|
||||||
@ -108,13 +106,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
for retry in range(DEFAULT_RETRY):
|
for retry in range(DEFAULT_RETRY):
|
||||||
try:
|
try:
|
||||||
payload = b64decode(packet)
|
payload = b64decode(packet)
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, broadlink_device.send_data, payload)
|
broadlink_device.send_data, payload)
|
||||||
break
|
break
|
||||||
except (socket.timeout, ValueError):
|
except (socket.timeout, ValueError):
|
||||||
try:
|
try:
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, broadlink_device.auth)
|
broadlink_device.auth)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
if retry == DEFAULT_RETRY-1:
|
if retry == DEFAULT_RETRY-1:
|
||||||
_LOGGER.error("Failed to send packet to device")
|
_LOGGER.error("Failed to send packet to device")
|
||||||
|
@ -179,8 +179,8 @@ def load_data(url=None, file=None, username=None, password=None):
|
|||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Set up the Telegram bot component."""
|
"""Set up the Telegram bot component."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -96,8 +96,8 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
hass.http.register_view(TextToSpeechView(tts))
|
hass.http.register_view(TextToSpeechView(tts))
|
||||||
|
|
||||||
descriptions = yield from hass.loop.run_in_executor(
|
descriptions = yield from hass.async_add_job(
|
||||||
None, load_yaml_config_file,
|
load_yaml_config_file,
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -113,8 +113,8 @@ def async_setup(hass, config):
|
|||||||
provider = yield from platform.async_get_engine(
|
provider = yield from platform.async_get_engine(
|
||||||
hass, p_config)
|
hass, p_config)
|
||||||
else:
|
else:
|
||||||
provider = yield from hass.loop.run_in_executor(
|
provider = yield from hass.async_add_job(
|
||||||
None, platform.get_engine, hass, p_config)
|
platform.get_engine, hass, p_config)
|
||||||
|
|
||||||
if provider is None:
|
if provider is None:
|
||||||
_LOGGER.error("Error setting up platform %s", p_type)
|
_LOGGER.error("Error setting up platform %s", p_type)
|
||||||
@ -207,8 +207,8 @@ class SpeechManager(object):
|
|||||||
return cache_dir
|
return cache_dir
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cache_dir = yield from self.hass.loop.run_in_executor(
|
self.cache_dir = yield from self.hass.async_add_job(
|
||||||
None, init_tts_cache_dir, cache_dir)
|
init_tts_cache_dir, cache_dir)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise HomeAssistantError("Can't init cache dir {}".format(err))
|
raise HomeAssistantError("Can't init cache dir {}".format(err))
|
||||||
|
|
||||||
@ -228,8 +228,7 @@ class SpeechManager(object):
|
|||||||
return cache
|
return cache
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cache_files = yield from self.hass.loop.run_in_executor(
|
cache_files = yield from self.hass.async_add_job(get_cache_files)
|
||||||
None, get_cache_files)
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise HomeAssistantError("Can't read cache dir {}".format(err))
|
raise HomeAssistantError("Can't read cache dir {}".format(err))
|
||||||
|
|
||||||
@ -250,7 +249,7 @@ class SpeechManager(object):
|
|||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Can't remove cache file '%s': %s", filename, err)
|
"Can't remove cache file '%s': %s", filename, err)
|
||||||
|
|
||||||
yield from self.hass.loop.run_in_executor(None, remove_files)
|
yield from self.hass.async_add_job(remove_files)
|
||||||
self.file_cache = {}
|
self.file_cache = {}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -355,7 +354,7 @@ class SpeechManager(object):
|
|||||||
speech.write(data)
|
speech.write(data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield from self.hass.loop.run_in_executor(None, save_speech)
|
yield from self.hass.async_add_job(save_speech)
|
||||||
self.file_cache[key] = filename
|
self.file_cache[key] = filename
|
||||||
except OSError:
|
except OSError:
|
||||||
_LOGGER.error("Can't write %s", filename)
|
_LOGGER.error("Can't write %s", filename)
|
||||||
@ -378,7 +377,7 @@ class SpeechManager(object):
|
|||||||
return speech.read()
|
return speech.read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = yield from self.hass.loop.run_in_executor(None, load_speech)
|
data = yield from self.hass.async_add_job(load_speech)
|
||||||
except OSError:
|
except OSError:
|
||||||
del self.file_cache[key]
|
del self.file_cache[key]
|
||||||
raise HomeAssistantError("Can't read {}".format(voice_file))
|
raise HomeAssistantError("Can't read {}".format(voice_file))
|
||||||
@ -490,9 +489,8 @@ class Provider(object):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(
|
ft.partial(self.get_tts_audio, message, language, options=options))
|
||||||
self.get_tts_audio, message, language, options=options))
|
|
||||||
|
|
||||||
|
|
||||||
class TextToSpeechView(HomeAssistantView):
|
class TextToSpeechView(HomeAssistantView):
|
||||||
|
@ -80,8 +80,8 @@ class GoogleProvider(Provider):
|
|||||||
|
|
||||||
data = b''
|
data = b''
|
||||||
for idx, part in enumerate(message_parts):
|
for idx, part in enumerate(message_parts):
|
||||||
part_token = yield from self.hass.loop.run_in_executor(
|
part_token = yield from self.hass.async_add_job(
|
||||||
None, token.calculate_token, part)
|
token.calculate_token, part)
|
||||||
|
|
||||||
url_param = {
|
url_param = {
|
||||||
'ie': 'UTF-8',
|
'ie': 'UTF-8',
|
||||||
|
@ -231,7 +231,7 @@ def async_hass_config_yaml(hass):
|
|||||||
conf = load_yaml_config_file(path)
|
conf = load_yaml_config_file(path)
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
conf = yield from hass.loop.run_in_executor(None, _load_hass_yaml_config)
|
conf = yield from hass.async_add_job(_load_hass_yaml_config)
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
@ -404,8 +404,8 @@ def async_process_ha_core_config(hass, config):
|
|||||||
# If we miss some of the needed values, auto detect them
|
# If we miss some of the needed values, auto detect them
|
||||||
if None in (hac.latitude, hac.longitude, hac.units,
|
if None in (hac.latitude, hac.longitude, hac.units,
|
||||||
hac.time_zone):
|
hac.time_zone):
|
||||||
info = yield from hass.loop.run_in_executor(
|
info = yield from hass.async_add_job(
|
||||||
None, loc_util.detect_location_info)
|
loc_util.detect_location_info)
|
||||||
|
|
||||||
if info is None:
|
if info is None:
|
||||||
_LOGGER.error('Could not detect location information')
|
_LOGGER.error('Could not detect location information')
|
||||||
@ -430,8 +430,8 @@ def async_process_ha_core_config(hass, config):
|
|||||||
|
|
||||||
if hac.elevation is None and hac.latitude is not None and \
|
if hac.elevation is None and hac.latitude is not None and \
|
||||||
hac.longitude is not None:
|
hac.longitude is not None:
|
||||||
elevation = yield from hass.loop.run_in_executor(
|
elevation = yield from hass.async_add_job(
|
||||||
None, loc_util.elevation, hac.latitude, hac.longitude)
|
loc_util.elevation, hac.latitude, hac.longitude)
|
||||||
hac.elevation = elevation
|
hac.elevation = elevation
|
||||||
discovered.append(('elevation', elevation))
|
discovered.append(('elevation', elevation))
|
||||||
|
|
||||||
|
@ -221,8 +221,7 @@ class Entity(object):
|
|||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
yield from self.async_update()
|
yield from self.async_update()
|
||||||
else:
|
else:
|
||||||
yield from self.hass.loop.run_in_executor(
|
yield from self.hass.async_add_job(self.update)
|
||||||
None, self.update)
|
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Update for %s fails", self.entity_id)
|
_LOGGER.exception("Update for %s fails", self.entity_id)
|
||||||
return
|
return
|
||||||
@ -363,8 +362,8 @@ class ToggleEntity(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.turn_on, **kwargs))
|
ft.partial(self.turn_on, **kwargs))
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
@ -375,8 +374,8 @@ class ToggleEntity(Entity):
|
|||||||
|
|
||||||
This method must be run in the event loop and returns a coroutine.
|
This method must be run in the event loop and returns a coroutine.
|
||||||
"""
|
"""
|
||||||
return self.hass.loop.run_in_executor(
|
return self.hass.async_add_job(
|
||||||
None, ft.partial(self.turn_off, **kwargs))
|
ft.partial(self.turn_off, **kwargs))
|
||||||
|
|
||||||
def toggle(self) -> None:
|
def toggle(self) -> None:
|
||||||
"""Toggle the entity."""
|
"""Toggle the entity."""
|
||||||
|
@ -151,8 +151,8 @@ class EntityComponent(object):
|
|||||||
entity_platform.async_schedule_add_entities, discovery_info
|
entity_platform.async_schedule_add_entities, discovery_info
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
task = self.hass.loop.run_in_executor(
|
task = self.hass.async_add_job(
|
||||||
None, platform.setup_platform, self.hass, platform_config,
|
platform.setup_platform, self.hass, platform_config,
|
||||||
entity_platform.schedule_add_entities, discovery_info
|
entity_platform.schedule_add_entities, discovery_info
|
||||||
)
|
)
|
||||||
yield from asyncio.wait_for(
|
yield from asyncio.wait_for(
|
||||||
@ -195,7 +195,7 @@ class EntityComponent(object):
|
|||||||
if hasattr(entity, 'async_update'):
|
if hasattr(entity, 'async_update'):
|
||||||
yield from entity.async_update()
|
yield from entity.async_update()
|
||||||
else:
|
else:
|
||||||
yield from self.hass.loop.run_in_executor(None, entity.update)
|
yield from self.hass.async_add_job(entity.update)
|
||||||
|
|
||||||
if getattr(entity, 'entity_id', None) is None:
|
if getattr(entity, 'entity_id', None) is None:
|
||||||
object_id = entity.name or DEVICE_DEFAULT_NAME
|
object_id = entity.name or DEVICE_DEFAULT_NAME
|
||||||
|
@ -76,8 +76,8 @@ def async_get_last_state(hass, entity_id: str):
|
|||||||
|
|
||||||
with (yield from hass.data[_LOCK]):
|
with (yield from hass.data[_LOCK]):
|
||||||
if DATA_RESTORE_CACHE not in hass.data:
|
if DATA_RESTORE_CACHE not in hass.data:
|
||||||
yield from hass.loop.run_in_executor(
|
yield from hass.async_add_job(
|
||||||
None, _load_restore_cache, hass)
|
_load_restore_cache, hass)
|
||||||
|
|
||||||
return hass.data.get(DATA_RESTORE_CACHE, {}).get(entity_id)
|
return hass.data.get(DATA_RESTORE_CACHE, {}).get(entity_id)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ def _async_process_requirements(hass: core.HomeAssistant, name: str,
|
|||||||
|
|
||||||
with (yield from pip_lock):
|
with (yield from pip_lock):
|
||||||
for req in requirements:
|
for req in requirements:
|
||||||
ret = yield from hass.loop.run_in_executor(None, pip_install, req)
|
ret = yield from hass.async_add_job(pip_install, req)
|
||||||
if not ret:
|
if not ret:
|
||||||
_LOGGER.error("Not initializing %s because could not install "
|
_LOGGER.error("Not initializing %s because could not install "
|
||||||
"dependency %s", name, req)
|
"dependency %s", name, req)
|
||||||
@ -184,8 +184,8 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||||||
if async_comp:
|
if async_comp:
|
||||||
result = yield from component.async_setup(hass, processed_config)
|
result = yield from component.async_setup(hass, processed_config)
|
||||||
else:
|
else:
|
||||||
result = yield from hass.loop.run_in_executor(
|
result = yield from hass.async_add_job(
|
||||||
None, component.setup, hass, processed_config)
|
component.setup, hass, processed_config)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Error during setup of component %s", domain)
|
_LOGGER.exception("Error during setup of component %s", domain)
|
||||||
async_notify_setup_error(hass, domain, True)
|
async_notify_setup_error(hass, domain, True)
|
||||||
|
@ -31,26 +31,21 @@ def test_generate_entity_id_given_keys():
|
|||||||
'test.another_entity']) == 'test.overwrite_hidden_true'
|
'test.another_entity']) == 'test.overwrite_hidden_true'
|
||||||
|
|
||||||
|
|
||||||
def test_async_update_support(event_loop):
|
def test_async_update_support(hass):
|
||||||
"""Test async update getting called."""
|
"""Test async update getting called."""
|
||||||
sync_update = []
|
sync_update = []
|
||||||
async_update = []
|
async_update = []
|
||||||
|
|
||||||
class AsyncEntity(entity.Entity):
|
class AsyncEntity(entity.Entity):
|
||||||
hass = MagicMock()
|
|
||||||
entity_id = 'sensor.test'
|
entity_id = 'sensor.test'
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
sync_update.append([1])
|
sync_update.append([1])
|
||||||
|
|
||||||
ent = AsyncEntity()
|
ent = AsyncEntity()
|
||||||
ent.hass.loop = event_loop
|
ent.hass = hass
|
||||||
|
|
||||||
@asyncio.coroutine
|
hass.loop.run_until_complete(ent.async_update_ha_state(True))
|
||||||
def test():
|
|
||||||
yield from ent.async_update_ha_state(True)
|
|
||||||
|
|
||||||
event_loop.run_until_complete(test())
|
|
||||||
|
|
||||||
assert len(sync_update) == 1
|
assert len(sync_update) == 1
|
||||||
assert len(async_update) == 0
|
assert len(async_update) == 0
|
||||||
@ -62,7 +57,7 @@ def test_async_update_support(event_loop):
|
|||||||
|
|
||||||
ent.async_update = async_update_func
|
ent.async_update = async_update_func
|
||||||
|
|
||||||
event_loop.run_until_complete(test())
|
hass.loop.run_until_complete(ent.async_update_ha_state(True))
|
||||||
|
|
||||||
assert len(sync_update) == 1
|
assert len(sync_update) == 1
|
||||||
assert len(async_update) == 1
|
assert len(async_update) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user