mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Schlage: Source valid auto lock times from pyschlage (#143382)
* Source auto lock times from pyschlage * Update auto lock strings * Test all options are translated
This commit is contained in:
parent
469176c59b
commit
a0c9217375
@ -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],
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user