mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 05:57:01 +00:00
Fix automations listening to HOMEASSISTANT_START (#6936)
* Fire EVENT_HOMEASSISTANT_START automations off right away while starting * Actually have core state be set to 'starting' during boot * Fix correct start implementation * Test and deprecate event automation platform on start * Fix doc strings * Remove shutting down exception * More strict when to mark an instance as finished * Add automation platform to listen for start/shutdown * When we stop we should wait till it's all done * Fix testing * Fix async bugs in tests * Only set UVLOOP when hass starts from CLI * This hangs normal asyncio event loop * Clean up Z-Wave node entity test
This commit is contained in:
@@ -23,12 +23,13 @@ import homeassistant.util.yaml as yaml
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
||||
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
|
||||
ATTR_DISCOVERED, SERVER_PORT, EVENT_HOMEASSISTANT_STOP)
|
||||
ATTR_DISCOVERED, SERVER_PORT, EVENT_HOMEASSISTANT_CLOSE)
|
||||
from homeassistant.components import sun, mqtt, recorder
|
||||
from homeassistant.components.http.auth import auth_middleware
|
||||
from homeassistant.components.http.const import (
|
||||
KEY_USE_X_FORWARDED_FOR, KEY_BANS_ENABLED, KEY_TRUSTED_NETWORKS)
|
||||
from homeassistant.util.async import run_callback_threadsafe
|
||||
from homeassistant.util.async import (
|
||||
run_callback_threadsafe, run_coroutine_threadsafe)
|
||||
|
||||
_TEST_INSTANCE_PORT = SERVER_PORT
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -58,15 +59,11 @@ def get_test_home_assistant():
|
||||
loop.run_forever()
|
||||
stop_event.set()
|
||||
|
||||
orig_start = hass.start
|
||||
orig_stop = hass.stop
|
||||
|
||||
@patch.object(hass.loop, 'run_forever')
|
||||
@patch.object(hass.loop, 'close')
|
||||
def start_hass(*mocks):
|
||||
"""Helper to start hass."""
|
||||
orig_start()
|
||||
hass.block_till_done()
|
||||
run_coroutine_threadsafe(hass.async_start(), loop=hass.loop).result()
|
||||
|
||||
def stop_hass():
|
||||
"""Stop hass."""
|
||||
@@ -101,7 +98,6 @@ def async_test_home_assistant(loop):
|
||||
return orig_async_add_job(target, *args)
|
||||
|
||||
hass.async_add_job = async_add_job
|
||||
hass.async_track_tasks()
|
||||
|
||||
hass.config.location_name = 'test home'
|
||||
hass.config.config_dir = get_test_config_dir()
|
||||
@@ -123,7 +119,11 @@ def async_test_home_assistant(loop):
|
||||
@asyncio.coroutine
|
||||
def mock_async_start():
|
||||
"""Start the mocking."""
|
||||
with patch('homeassistant.core._async_create_timer'):
|
||||
# 1. We only mock time during tests
|
||||
# 2. We want block_till_done that is called inside stop_track_tasks
|
||||
with patch('homeassistant.core._async_create_timer'), \
|
||||
patch.object(hass, 'async_stop_track_tasks',
|
||||
hass.async_block_till_done):
|
||||
yield from orig_start()
|
||||
|
||||
hass.async_start = mock_async_start
|
||||
@@ -134,7 +134,7 @@ def async_test_home_assistant(loop):
|
||||
global INST_COUNT
|
||||
INST_COUNT -= 1
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, clear_instance)
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, clear_instance)
|
||||
|
||||
return hass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user