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

Add filter to translation event listeners to avoid creating tasks (#110732)

This commit is contained in:
J. Nick Koston
2024-02-16 12:13:23 -06:00
committed by GitHub
parent 6f74ea9186
commit 2cb0249f0a
2 changed files with 57 additions and 14 deletions

View File

@@ -602,12 +602,21 @@ async def test_setup(hass: HomeAssistant):
await hass.async_block_till_done()
mock.assert_not_called()
# Should not be called if the language is the current language
with patch(
"homeassistant.helpers.translation._async_load_state_translations_to_cache",
) as mock:
hass.bus.async_fire(EVENT_CORE_CONFIG_UPDATE, {"language": "en"})
await hass.async_block_till_done()
mock.assert_called_once_with(hass, hass.config.language, None)
mock.assert_not_called()
# Should be called if the language is different
with patch(
"homeassistant.helpers.translation._async_load_state_translations_to_cache",
) as mock:
hass.bus.async_fire(EVENT_CORE_CONFIG_UPDATE, {"language": "es"})
await hass.async_block_till_done()
mock.assert_called_once_with(hass, "es", None)
with patch(
"homeassistant.helpers.translation._async_load_state_translations_to_cache",