1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Avoid creating unneeded Context and Event objects when firing events (#113798)

* Avoid creating unneeded Context and Event objects when firing events

* Add test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Erik Montnemery
2024-03-20 09:40:06 +01:00
committed by GitHub
parent 638020f168
commit d31124d5d4
19 changed files with 257 additions and 128 deletions

View File

@@ -492,11 +492,11 @@ def async_setup(hass: HomeAssistant) -> None:
hass.data[TRANSLATION_FLATTEN_CACHE] = cache
@callback
def _async_load_translations_filter(event: Event) -> bool:
def _async_load_translations_filter(event_data: Mapping[str, Any]) -> bool:
"""Filter out unwanted events."""
nonlocal current_language
if (
new_language := event.data.get("language")
new_language := event_data.get("language")
) and new_language != current_language:
current_language = new_language
return True