Skip to content

Commit

Permalink
Simplify configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMachowski committed Jun 11, 2024
1 parent bd45dd1 commit 300b8bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions custom_components/custom_templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
if DOMAIN not in config:
return True
languages = []
if CONF_PRELOAD_TRANSLATIONS in config[DOMAIN]:
if CONF_PRELOAD_TRANSLATIONS in config[DOMAIN] and len(config[DOMAIN][CONF_PRELOAD_TRANSLATIONS]) > 0:
languages = config[DOMAIN][CONF_PRELOAD_TRANSLATIONS]
cache: _TranslationCache = hass.data[TRANSLATION_FLATTEN_CACHE]

async def _async_load_translations(_: Event) -> None:
for language in languages:
_LOGGER.debug("Loading translations for language: %s", language)
_
await cache.async_load(language, hass.config.components)

hass.bus.async_listen(
EVENT_COMPONENT_LOADED,
_async_load_translations
)
else:
languages = [hass.config.language]
cache: _TranslationCache = hass.data[TRANSLATION_FLATTEN_CACHE]

async def _async_load_translations(_: Event) -> None:
for language in languages:
_LOGGER.debug("Loading translations for language: %s", language)
components = set(filter(lambda c: "." not in c, hass.config.components))
await cache.async_load(language, components)

hass.bus.async_listen(
EVENT_COMPONENT_LOADED,
_async_load_translations
)

state_translated_template = StateTranslated(hass, languages)
state_attr_translated_template = StateAttrTranslated(hass, languages)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/custom_templates/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CUSTOM_TEMPLATES_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema({
vol.Required(CONF_PRELOAD_TRANSLATIONS): cv.ensure_list(cv.string)
vol.Optional(CONF_PRELOAD_TRANSLATIONS): cv.ensure_list(cv.string)
})
},
extra=vol.ALLOW_EXTRA
Expand Down

0 comments on commit 300b8bb

Please sign in to comment.