mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Black
This commit is contained in:
@@ -10,62 +10,59 @@ from tests.common import async_mock_service, mock_coro
|
||||
|
||||
async def test_if_fires_on_hass_start(hass):
|
||||
"""Test the firing when HASS starts."""
|
||||
calls = async_mock_service(hass, 'test', 'automation')
|
||||
calls = async_mock_service(hass, "test", "automation")
|
||||
hass.state = CoreState.not_running
|
||||
config = {
|
||||
automation.DOMAIN: {
|
||||
'alias': 'hello',
|
||||
'trigger': {
|
||||
'platform': 'homeassistant',
|
||||
'event': 'start',
|
||||
},
|
||||
'action': {
|
||||
'service': 'test.automation',
|
||||
}
|
||||
"alias": "hello",
|
||||
"trigger": {"platform": "homeassistant", "event": "start"},
|
||||
"action": {"service": "test.automation"},
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, automation.DOMAIN, config)
|
||||
assert automation.is_on(hass, 'automation.hello')
|
||||
assert automation.is_on(hass, "automation.hello")
|
||||
assert len(calls) == 0
|
||||
|
||||
await hass.async_start()
|
||||
assert automation.is_on(hass, 'automation.hello')
|
||||
assert automation.is_on(hass, "automation.hello")
|
||||
assert len(calls) == 1
|
||||
|
||||
with patch('homeassistant.config.async_hass_config_yaml',
|
||||
Mock(return_value=mock_coro(config))):
|
||||
with patch(
|
||||
"homeassistant.config.async_hass_config_yaml",
|
||||
Mock(return_value=mock_coro(config)),
|
||||
):
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True)
|
||||
automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True
|
||||
)
|
||||
|
||||
assert automation.is_on(hass, 'automation.hello')
|
||||
assert automation.is_on(hass, "automation.hello")
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_hass_shutdown(hass):
|
||||
"""Test the firing when HASS starts."""
|
||||
calls = async_mock_service(hass, 'test', 'automation')
|
||||
calls = async_mock_service(hass, "test", "automation")
|
||||
hass.state = CoreState.not_running
|
||||
|
||||
assert await async_setup_component(hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'alias': 'hello',
|
||||
'trigger': {
|
||||
'platform': 'homeassistant',
|
||||
'event': 'shutdown',
|
||||
},
|
||||
'action': {
|
||||
'service': 'test.automation',
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
automation.DOMAIN,
|
||||
{
|
||||
automation.DOMAIN: {
|
||||
"alias": "hello",
|
||||
"trigger": {"platform": "homeassistant", "event": "shutdown"},
|
||||
"action": {"service": "test.automation"},
|
||||
}
|
||||
}
|
||||
})
|
||||
assert automation.is_on(hass, 'automation.hello')
|
||||
},
|
||||
)
|
||||
assert automation.is_on(hass, "automation.hello")
|
||||
assert len(calls) == 0
|
||||
|
||||
await hass.async_start()
|
||||
assert automation.is_on(hass, 'automation.hello')
|
||||
assert automation.is_on(hass, "automation.hello")
|
||||
assert len(calls) == 0
|
||||
|
||||
with patch.object(hass.loop, 'stop'):
|
||||
with patch.object(hass.loop, "stop"):
|
||||
await hass.async_stop()
|
||||
assert len(calls) == 1
|
||||
|
||||
Reference in New Issue
Block a user