Add async_safe annotation (#3688)

* Add async_safe annotation

* More async_run_job

* coroutine -> async_save

* Lint

* Rename async_safe -> callback

* Add tests to core for different job types

* Add one more test with different type of callbacks

* Fix typing signature for callback methods

* Fix callback service executed method

* Fix method signatures for callback
This commit is contained in:
Paulus Schoutsen 2016-10-04 20:44:32 -07:00 committed by GitHub
parent be7401f4a2
commit 5085cdb0f7
19 changed files with 231 additions and 87 deletions

View file

@ -4,11 +4,11 @@ Offer numeric state listening automation rules.
For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation/#numeric-state-trigger
"""
import asyncio
import logging
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.const import (
CONF_VALUE_TEMPLATE, CONF_PLATFORM, CONF_ENTITY_ID,
CONF_BELOW, CONF_ABOVE)
@ -35,7 +35,7 @@ def async_trigger(hass, config, action):
if value_template is not None:
value_template.hass = hass
@asyncio.coroutine
@callback
def state_automation_listener(entity, from_s, to_s):
"""Listen for state changes and calls action."""
if to_s is None:
@ -64,6 +64,6 @@ def async_trigger(hass, config, action):
variables['trigger']['from_state'] = from_s
variables['trigger']['to_state'] = to_s
hass.async_add_job(action, variables)
hass.async_run_job(action, variables)
return async_track_state_change(hass, entity_id, state_automation_listener)