Add support for opening state in template lock (#147813)

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
nadimz 2025-07-01 23:03:20 +02:00 committed by GitHub
parent a6146fb5a9
commit 392cde20d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -193,6 +193,11 @@ class AbstractTemplateLock(AbstractTemplateEntity, LockEntity):
"""Return true if lock is open."""
return self._state == LockState.OPEN
@property
def is_opening(self) -> bool:
"""Return true if lock is opening."""
return self._state == LockState.OPENING
@property
def code_format(self) -> str | None:
"""Regex for code format or None if no code is required."""

View File

@ -307,19 +307,19 @@ async def test_template_state(hass: HomeAssistant) -> None:
hass.states.async_set(TEST_STATE_ENTITY_ID, STATE_ON)
await hass.async_block_till_done()
state = hass.states.get("lock.test_template_lock")
state = hass.states.get(TEST_ENTITY_ID)
assert state.state == LockState.LOCKED
hass.states.async_set(TEST_STATE_ENTITY_ID, STATE_OFF)
await hass.async_block_till_done()
state = hass.states.get("lock.test_template_lock")
state = hass.states.get(TEST_ENTITY_ID)
assert state.state == LockState.UNLOCKED
hass.states.async_set(TEST_STATE_ENTITY_ID, STATE_OPEN)
await hass.async_block_till_done()
state = hass.states.get("lock.test_template_lock")
state = hass.states.get(TEST_ENTITY_ID)
assert state.state == LockState.OPEN
@ -888,7 +888,16 @@ async def test_actions_with_invalid_regexp_as_codeformat_never_execute(
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
)
@pytest.mark.parametrize(
"test_state", [LockState.UNLOCKING, LockState.LOCKING, LockState.JAMMED]
"test_state",
[
LockState.LOCKED,
LockState.UNLOCKED,
LockState.OPEN,
LockState.UNLOCKING,
LockState.LOCKING,
LockState.JAMMED,
LockState.OPENING,
],
)
@pytest.mark.usefixtures("setup_state_lock")
async def test_lock_state(hass: HomeAssistant, test_state) -> None: