diff --git a/homeassistant/components/schlage/select.py b/homeassistant/components/schlage/select.py index 4648686aaac..cb142f01717 100644 --- a/homeassistant/components/schlage/select.py +++ b/homeassistant/components/schlage/select.py @@ -2,6 +2,8 @@ from __future__ import annotations +from pyschlage.lock import AUTO_LOCK_TIMES + from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant @@ -15,16 +17,7 @@ _DESCRIPTIONS = ( key="auto_lock_time", translation_key="auto_lock_time", entity_category=EntityCategory.CONFIG, - # valid values are from Schlage UI and validated by pyschlage - options=[ - "0", - "15", - "30", - "60", - "120", - "240", - "300", - ], + options=[str(n) for n in AUTO_LOCK_TIMES], ), ) diff --git a/homeassistant/components/schlage/strings.json b/homeassistant/components/schlage/strings.json index 42bd51de9d0..e37f4789580 100644 --- a/homeassistant/components/schlage/strings.json +++ b/homeassistant/components/schlage/strings.json @@ -36,6 +36,7 @@ "name": "Auto-lock time", "state": { "0": "[%key:common::state::disabled%]", + "5": "5 seconds", "15": "15 seconds", "30": "30 seconds", "60": "1 minute", diff --git a/tests/components/schlage/test_select.py b/tests/components/schlage/test_select.py index 59ff065d449..c18ceb0ec8e 100644 --- a/tests/components/schlage/test_select.py +++ b/tests/components/schlage/test_select.py @@ -2,13 +2,17 @@ from unittest.mock import Mock +from pyschlage.lock import AUTO_LOCK_TIMES + +from homeassistant.components.schlage.const import DOMAIN from homeassistant.components.select import ( ATTR_OPTION, DOMAIN as SELECT_DOMAIN, SERVICE_SELECT_OPTION, ) -from homeassistant.const import ATTR_ENTITY_ID +from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers.translation import LOCALE_EN, async_get_translations from . import MockSchlageConfigEntry @@ -32,3 +36,12 @@ async def test_select( blocking=True, ) mock_lock.set_auto_lock_time.assert_called_once_with(30) + + +async def test_auto_lock_time_translations(hass: HomeAssistant) -> None: + """Test all auto_lock_time select options are translated.""" + prefix = f"component.{DOMAIN}.entity.{Platform.SELECT.value}.auto_lock_time.state." + translations = await async_get_translations(hass, LOCALE_EN, "entity", [DOMAIN]) + got_translation_states = {k for k in translations if k.startswith(prefix)} + want_translation_states = {f"{prefix}{t}" for t in AUTO_LOCK_TIMES} + assert want_translation_states == got_translation_states