Spread async love (#3575)
* Convert Entity.update_ha_state to be async * Make Service.call async * Update entity.py * Add Entity.async_update * Make automation zone trigger async * Fix linting * Reduce flakiness in hass.block_till_done * Make automation.numeric_state async * Make mqtt.subscribe async * Make automation.mqtt async * Make automation.time async * Make automation.sun async * Add async_track_point_in_utc_time * Make helpers.track_sunrise/set async * Add async_track_state_change * Make automation.state async * Clean up helpers/entity.py tests * Lint * Lint * Core.is_state and Core.is_state_attr are async friendly * Lint * Lint
This commit is contained in:
1 parent
7e50ccd32a
commit
b650b2b0db
17 files changed
+323
-151
No files matched your search
@@ -84,6 +84,15 @@ def or_from_config(config: ConfigType, config_validation: bool=True):
|
||||
def numeric_state(hass: HomeAssistant, entity, below=None, above=None,
|
||||
value_template=None, variables=None):
|
||||
"""Test a numeric state condition."""
|
||||
return run_callback_threadsafe(
|
||||
hass.loop, async_numeric_state, hass, entity, below, above,
|
||||
value_template, variables,
|
||||
).result()
|
||||
|
||||
|
||||
def async_numeric_state(hass: HomeAssistant, entity, below=None, above=None,
|
||||
value_template=None, variables=None):
|
||||
"""Test a numeric state condition."""
|
||||
if isinstance(entity, str):
|
||||
entity = hass.states.get(entity)
|
||||
|
||||
@@ -96,7 +105,7 @@ def numeric_state(hass: HomeAssistant, entity, below=None, above=None,
|
||||
variables = dict(variables or {})
|
||||
variables['state'] = entity
|
||||
try:
|
||||
value = value_template.render(variables)
|
||||
value = value_template.async_render(variables)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error("Template error: %s", ex)
|
||||
return False
|
||||
@@ -290,7 +299,10 @@ def time_from_config(config, config_validation=True):
|
||||
|
||||
|
||||
def zone(hass, zone_ent, entity):
|
||||
"""Test if zone-condition matches."""
|
||||
"""Test if zone-condition matches.
|
||||
|
||||
Can be run async.
|
||||
"""
|
||||
if isinstance(zone_ent, str):
|
||||
zone_ent = hass.states.get(zone_ent)
|
||||
|
||||
|
||||
Reference in new issue
Block a user