-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
23 changed files
with
262 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Offer Home Assistant core automation rules. | ||
For more details about this automation rule, please refer to the documentation | ||
at https://home-assistant.io/components/automation/#homeassistant-trigger | ||
""" | ||
import asyncio | ||
import logging | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.core import callback, CoreState | ||
from homeassistant.const import ( | ||
CONF_PLATFORM, CONF_EVENT, EVENT_HOMEASSISTANT_STOP) | ||
|
||
EVENT_START = 'start' | ||
EVENT_SHUTDOWN = 'shutdown' | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
TRIGGER_SCHEMA = vol.Schema({ | ||
vol.Required(CONF_PLATFORM): 'homeassistant', | ||
vol.Required(CONF_EVENT): vol.Any(EVENT_START, EVENT_SHUTDOWN), | ||
}) | ||
|
||
|
||
@asyncio.coroutine | ||
def async_trigger(hass, config, action): | ||
"""Listen for events based on configuration.""" | ||
event = config.get(CONF_EVENT) | ||
|
||
if event == EVENT_SHUTDOWN: | ||
@callback | ||
def hass_shutdown(event): | ||
"""Called when Home Assistant is shutting down.""" | ||
hass.async_run_job(action, { | ||
'trigger': { | ||
'platform': 'homeassistant', | ||
'event': event, | ||
}, | ||
}) | ||
|
||
return hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, | ||
hass_shutdown) | ||
|
||
# Automation are enabled while hass is starting up, fire right away | ||
# Check state because a config reload shouldn't trigger it. | ||
elif hass.state == CoreState.starting: | ||
hass.async_run_job(action, { | ||
'trigger': { | ||
'platform': 'homeassistant', | ||
'event': event, | ||
}, | ||
}) | ||
|
||
return lambda: None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.