Add async_get_hass_or_none (#118164)
This commit is contained in:
parent
05c24e92d1
commit
c368ffffd5
7 changed files with 30 additions and 44 deletions
|
@ -93,8 +93,8 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import (
|
||||
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||
HomeAssistant,
|
||||
async_get_hass,
|
||||
async_get_hass_or_none,
|
||||
split_entity_id,
|
||||
valid_entity_id,
|
||||
)
|
||||
|
@ -662,11 +662,7 @@ def template(value: Any | None) -> template_helper.Template:
|
|||
if isinstance(value, (list, dict, template_helper.Template)):
|
||||
raise vol.Invalid("template value should be a string")
|
||||
|
||||
hass: HomeAssistant | None = None
|
||||
with contextlib.suppress(HomeAssistantError):
|
||||
hass = async_get_hass()
|
||||
|
||||
template_value = template_helper.Template(str(value), hass)
|
||||
template_value = template_helper.Template(str(value), async_get_hass_or_none())
|
||||
|
||||
try:
|
||||
template_value.ensure_valid()
|
||||
|
@ -684,11 +680,7 @@ def dynamic_template(value: Any | None) -> template_helper.Template:
|
|||
if not template_helper.is_template_string(str(value)):
|
||||
raise vol.Invalid("template value does not contain a dynamic template")
|
||||
|
||||
hass: HomeAssistant | None = None
|
||||
with contextlib.suppress(HomeAssistantError):
|
||||
hass = async_get_hass()
|
||||
|
||||
template_value = template_helper.Template(str(value), hass)
|
||||
template_value = template_helper.Template(str(value), async_get_hass_or_none())
|
||||
|
||||
try:
|
||||
template_value.ensure_valid()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue