1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +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:
Paulus Schoutsen
2017-04-05 23:23:02 -07:00
committed by GitHub
parent 289d6b6605
commit 29f385ea76
23 changed files with 258 additions and 97 deletions

View File

@@ -1,11 +1,13 @@
"""The tests for the Event automation."""
import asyncio
import unittest
from homeassistant.core import callback
from homeassistant.setup import setup_component
from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.core import callback, CoreState
from homeassistant.setup import setup_component, async_setup_component
import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant, mock_component
from tests.common import get_test_home_assistant, mock_component, mock_service
# pylint: disable=invalid-name
@@ -92,3 +94,30 @@ class TestAutomationEvent(unittest.TestCase):
self.hass.bus.fire('test_event', {'some_attr': 'some_other_value'})
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
@asyncio.coroutine
def test_if_fires_on_event_with_data(hass):
"""Test the firing of events with data."""
calls = mock_service(hass, 'test', 'automation')
hass.state = CoreState.not_running
res = yield from async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'trigger': {
'platform': 'event',
'event_type': EVENT_HOMEASSISTANT_START,
},
'action': {
'service': 'test.automation',
}
}
})
assert res
assert not automation.is_on(hass, 'automation.hello')
assert len(calls) == 0
yield from hass.async_start()
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 1