Conversation reload with language=None clears all languages (#103757)

Reload with language=None clears all languages
This commit is contained in:
Michael Hansen 2023-11-10 12:22:49 -06:00 committed by GitHub
parent 253e6188eb
commit e157206eeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View file

@ -368,10 +368,11 @@ class DefaultAgent(AbstractConversationAgent):
async def async_reload(self, language: str | None = None):
"""Clear cached intents for a language."""
if language is None:
language = self.hass.config.language
self._lang_intents.pop(language, None)
_LOGGER.debug("Cleared intents for language: %s", language)
self._lang_intents.clear()
_LOGGER.debug("Cleared intents for all languages")
else:
self._lang_intents.pop(language, None)
_LOGGER.debug("Cleared intents for language: %s", language)
async def async_prepare(self, language: str | None = None):
"""Load intents for a language."""

View file

@ -1307,7 +1307,14 @@ async def test_prepare_reload(hass: HomeAssistant) -> None:
# Confirm intents are loaded
assert agent._lang_intents.get(language)
# Clear cache
# Try to clear for a different language
await hass.services.async_call("conversation", "reload", {"language": "elvish"})
await hass.async_block_till_done()
# Confirm intents are still loaded
assert agent._lang_intents.get(language)
# Clear cache for all languages
await hass.services.async_call("conversation", "reload", {})
await hass.async_block_till_done()