lock_reproduce_state (#27203)
This commit is contained in:
1 parent
0be1269b20
commit
cc4926afb1
2 files changed
+114
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""Test reproduce state for Lock."""
|
||||
from homeassistant.core import State
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
|
||||
async def test_reproducing_states(hass, caplog):
|
||||
"""Test reproducing Lock states."""
|
||||
hass.states.async_set("lock.entity_locked", "locked", {})
|
||||
hass.states.async_set("lock.entity_unlocked", "unlocked", {})
|
||||
|
||||
lock_calls = async_mock_service(hass, "lock", "lock")
|
||||
unlock_calls = async_mock_service(hass, "lock", "unlock")
|
||||
|
||||
# These calls should do nothing as entities already in desired state
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[
|
||||
State("lock.entity_locked", "locked"),
|
||||
State("lock.entity_unlocked", "unlocked", {}),
|
||||
],
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(lock_calls) == 0
|
||||
assert len(unlock_calls) == 0
|
||||
|
||||
# Test invalid state is handled
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State("lock.entity_locked", "not_supported")], blocking=True
|
||||
)
|
||||
|
||||
assert "not_supported" in caplog.text
|
||||
assert len(lock_calls) == 0
|
||||
assert len(unlock_calls) == 0
|
||||
|
||||
# Make sure correct services are called
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[
|
||||
State("lock.entity_locked", "unlocked"),
|
||||
State("lock.entity_unlocked", "locked"),
|
||||
# Should not raise
|
||||
State("lock.non_existing", "on"),
|
||||
],
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(lock_calls) == 1
|
||||
assert lock_calls[0].domain == "lock"
|
||||
assert lock_calls[0].data == {"entity_id": "lock.entity_unlocked"}
|
||||
|
||||
assert len(unlock_calls) == 1
|
||||
assert unlock_calls[0].domain == "lock"
|
||||
assert unlock_calls[0].data == {"entity_id": "lock.entity_locked"}
|
||||
Reference in new issue
Block a user