Skip to content

Commit

Permalink
Speed up async_render_with_possible_json_value (#118080)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 25, 2024
1 parent 3416162 commit 5cb3bc1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import base64
import collections.abc
from collections.abc import Callable, Generator, Iterable
from contextlib import AbstractContextManager, suppress
from contextlib import AbstractContextManager
from contextvars import ContextVar
from datetime import date, datetime, time, timedelta
from functools import cache, lru_cache, partial, wraps
Expand Down Expand Up @@ -759,8 +759,10 @@ def async_render_with_possible_json_value(
variables = dict(variables or {})
variables["value"] = value

with suppress(*JSON_DECODE_EXCEPTIONS):
try: # noqa: SIM105 - suppress is much slower
variables["value_json"] = json_loads(value)
except JSON_DECODE_EXCEPTIONS:
pass

try:
render_result = _render_with_context(
Expand Down

0 comments on commit 5cb3bc1

Please sign in to comment.