From 5cb3bc19c058e04016b7c2d50b0a06934ee751d0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 24 May 2024 17:43:42 -1000 Subject: [PATCH] Speed up async_render_with_possible_json_value (#118080) --- homeassistant/helpers/template.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 8c972a26cc5..131a51cb6ff 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -7,7 +7,7 @@ import asyncio 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 @@ -759,8 +759,10 @@ class Template: 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(