|
|
@@ -6,7 +6,7 @@ from pytest_homeassistant_custom_component.common import flush_store
|
|
|
|
|
|
from custom_components.zlock_slots.coordinator import ZLockCoordinator
|
|
|
from custom_components.zlock_slots.const import (
|
|
|
- DOMAIN, CONF_LOCK_ENTITY_IDS, CONF_GROUPS, CONF_GROUP_NAME,
|
|
|
+ DOMAIN, CONF_LOCK_ENTITY_IDS, CONF_GROUPS, CONF_GROUP_NAME, LockAction,
|
|
|
)
|
|
|
from tests.conftest import (
|
|
|
LOCK_ENTITY_ID, ALARM_TYPE_ENTITY, ALARM_LEVEL_ENTITY,
|
|
|
@@ -129,7 +129,7 @@ async def test_keypad_lock_sets_action_and_user(hass, coord):
|
|
|
hass.states.async_set(ALARM_TYPE_ENTITY, "18")
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "locked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.LOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "1"
|
|
|
|
|
|
|
|
|
@@ -144,31 +144,31 @@ async def test_keypad_lock_uses_slot_name(hass, coord):
|
|
|
|
|
|
async def test_keypad_unlock(hass, coord):
|
|
|
await _fire_alarm(hass, "19", alarm_level="2")
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "2"
|
|
|
|
|
|
|
|
|
async def test_manual_lock(hass, coord):
|
|
|
await _fire_alarm(hass, "21")
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "locked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.LOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "<Manual>"
|
|
|
|
|
|
|
|
|
async def test_manual_unlock(hass, coord):
|
|
|
await _fire_alarm(hass, "22")
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "<Manual>"
|
|
|
|
|
|
|
|
|
async def test_radio_lock(hass, coord):
|
|
|
await _fire_alarm(hass, "24")
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "locked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.LOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "<Radio>"
|
|
|
|
|
|
|
|
|
async def test_radio_unlock(hass, coord):
|
|
|
await _fire_alarm(hass, "25")
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "<Radio>"
|
|
|
|
|
|
|
|
|
@@ -198,7 +198,7 @@ async def test_alarm_type_before_level_resolves_when_level_arrives(hass, coord):
|
|
|
# Now alarm_level arrives — should resolve the pending action.
|
|
|
hass.states.async_set(ALARM_LEVEL_ENTITY, "87")
|
|
|
await hass.async_block_till_done()
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "87"
|
|
|
|
|
|
|
|
|
@@ -228,7 +228,7 @@ async def test_stale_alarm_level_not_used(hass, coord):
|
|
|
# Fresh level arrives and resolves the pending action.
|
|
|
hass.states.async_set(ALARM_LEVEL_ENTITY, "87")
|
|
|
await hass.async_block_till_done()
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert coord.data[LOCK_ENTITY_ID].last_user == "87"
|
|
|
|
|
|
|
|
|
@@ -241,7 +241,7 @@ async def test_new_alarm_type_clears_pending_slot_alarm(hass, coord):
|
|
|
hass.states.async_set(ALARM_LEVEL_ENTITY, "5")
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
- assert coord.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert coord.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
@@ -261,7 +261,7 @@ async def test_last_events_persisted_after_alarm(hass, config_entry, mock_node):
|
|
|
|
|
|
stored = await c._store.async_load()
|
|
|
|
|
|
- assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "locked"
|
|
|
+ assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "Locked"
|
|
|
assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_user"] == "1"
|
|
|
c.async_teardown()
|
|
|
|
|
|
@@ -281,7 +281,7 @@ async def test_last_events_restored_on_startup(hass, config_entry, mock_node):
|
|
|
c2 = ZLockCoordinator(hass, config_entry)
|
|
|
await c2.async_setup()
|
|
|
|
|
|
- assert c2.data[LOCK_ENTITY_ID].last_action == "unlocked"
|
|
|
+ assert c2.data[LOCK_ENTITY_ID].last_action == LockAction.UNLOCKED
|
|
|
assert c2.data[LOCK_ENTITY_ID].last_user == "<Manual>"
|
|
|
c2.async_teardown()
|
|
|
|
|
|
@@ -299,7 +299,7 @@ async def test_names_still_present_after_alarm_save(hass, config_entry, mock_nod
|
|
|
stored = await c._store.async_load()
|
|
|
|
|
|
assert stored["names"][f"{LOCK_ENTITY_ID}:1"] == "Alice"
|
|
|
- assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "locked"
|
|
|
+ assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "Locked"
|
|
|
c.async_teardown()
|
|
|
|
|
|
|
|
|
@@ -321,7 +321,7 @@ async def test_alarm_saves_are_debounced(hass, coord):
|
|
|
assert len(calls) == 1 # single coalesced write
|
|
|
|
|
|
stored = await coord._store.async_load()
|
|
|
- assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "unlocked"
|
|
|
+ assert stored["last_events"]["locks"][LOCK_ENTITY_ID]["last_action"] == "Unlocked"
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
@@ -351,7 +351,7 @@ async def test_group_state_updated_on_alarm(hass, group_config_entry, mock_node)
|
|
|
await c.async_setup()
|
|
|
await _fire_alarm(hass, "19", "1")
|
|
|
|
|
|
- assert c.group_data["All Locks"].last_action == "unlocked"
|
|
|
+ assert c.group_data["All Locks"].last_action == LockAction.UNLOCKED
|
|
|
assert c.group_data["All Locks"].last_user == "1"
|
|
|
c.async_teardown()
|
|
|
|
|
|
@@ -368,6 +368,6 @@ async def test_group_last_events_restored(hass, group_config_entry, mock_node):
|
|
|
c2 = ZLockCoordinator(hass, group_config_entry)
|
|
|
await c2.async_setup()
|
|
|
|
|
|
- assert c2.group_data["All Locks"].last_action == "locked"
|
|
|
+ assert c2.group_data["All Locks"].last_action == LockAction.LOCKED
|
|
|
assert c2.group_data["All Locks"].last_user == "<Radio>"
|
|
|
c2.async_teardown()
|