|
|
@@ -13,7 +13,7 @@ from custom_components.room_cal_ha.const import (
|
|
|
CONF_CALENDAR_NAME,
|
|
|
CONF_RESERVATION_DEFAULTS,
|
|
|
CONF_SYNC_MODE,
|
|
|
- CONF_ZWAVE_LOCKS,
|
|
|
+ CONF_ZLOCK_ENTRIES,
|
|
|
CONF_ZWAVE_SLOT,
|
|
|
DOMAIN,
|
|
|
STORE_CURRENT,
|
|
|
@@ -866,9 +866,16 @@ async def test_unifi_diff_key_check_skipped_when_actual_key_none(coordinator):
|
|
|
assert not diff.has_changes
|
|
|
|
|
|
|
|
|
+def _make_zlock_entry(hass, lock_entity_ids: list[str]) -> MockConfigEntry:
|
|
|
+ zlock = MockConfigEntry(domain="zlock_slots", data={"lock_entity_ids": lock_entity_ids})
|
|
|
+ zlock.add_to_hass(hass)
|
|
|
+ return zlock
|
|
|
+
|
|
|
+
|
|
|
@pytest.fixture
|
|
|
async def coordinator_with_locks(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_ZWAVE_LOCKS: ["lock.front_door"], CONF_ZWAVE_SLOT: 5})
|
|
|
+ zlock = _make_zlock_entry(hass, ["lock.front_door"])
|
|
|
+ entry = _make_entry(hass, {CONF_ZLOCK_ENTRIES: [zlock.entry_id], CONF_ZWAVE_SLOT: 5})
|
|
|
coord = RoomCalCoordinator(hass, entry)
|
|
|
await coord.async_setup()
|
|
|
return coord
|
|
|
@@ -905,17 +912,19 @@ async def test_check_in_sets_lock_codes(hass: HomeAssistant, coordinator_with_lo
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=True),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode", new_callable=AsyncMock) as mock_set,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_in()
|
|
|
coordinator_with_locks.cancel_mode_sync()
|
|
|
|
|
|
- mock_set.assert_awaited_once_with(hass, "lock.front_door", 5, "7890")
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_code", {"lock_entity_id": "lock.front_door", "slot": 5, "code": "7890"}, blocking=True)
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_slot_enabled", {"lock_entity_id": "lock.front_door", "slot": 5, "enabled": True}, blocking=True)
|
|
|
mock_switch.async_turn_on.assert_awaited_once()
|
|
|
|
|
|
|
|
|
async def test_check_in_sets_codes_on_all_locks(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_ZWAVE_LOCKS: ["lock.front", "lock.back"], CONF_ZWAVE_SLOT: 5})
|
|
|
+ zlock = _make_zlock_entry(hass, ["lock.front", "lock.back"])
|
|
|
+ entry = _make_entry(hass, {CONF_ZLOCK_ENTRIES: [zlock.entry_id], CONF_ZWAVE_SLOT: 5})
|
|
|
coord = RoomCalCoordinator(hass, entry)
|
|
|
await coord.async_setup()
|
|
|
await coord.store.async_set(STORE_NEXT, _ZWAVE_RES)
|
|
|
@@ -927,14 +936,15 @@ async def test_check_in_sets_codes_on_all_locks(hass: HomeAssistant):
|
|
|
patch.object(coord, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coord, "_is_use_zwave_on", return_value=True),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode", new_callable=AsyncMock) as mock_set,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coord._async_do_check_in()
|
|
|
coord.cancel_mode_sync()
|
|
|
|
|
|
- assert mock_set.await_count == 2
|
|
|
- mock_set.assert_any_await(hass, "lock.front", 5, "7890")
|
|
|
- mock_set.assert_any_await(hass, "lock.back", 5, "7890")
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_code", {"lock_entity_id": "lock.front", "slot": 5, "code": "7890"}, blocking=True)
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_code", {"lock_entity_id": "lock.back", "slot": 5, "code": "7890"}, blocking=True)
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_slot_enabled", {"lock_entity_id": "lock.front", "slot": 5, "enabled": True}, blocking=True)
|
|
|
+ mock_call.assert_any_await("zlock_slots", "set_slot_enabled", {"lock_entity_id": "lock.back", "slot": 5, "enabled": True}, blocking=True)
|
|
|
|
|
|
|
|
|
async def test_check_in_skips_lock_codes_when_door_code_none(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
@@ -953,12 +963,14 @@ async def test_check_in_skips_lock_codes_when_door_code_none(hass: HomeAssistant
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=True),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode", new_callable=AsyncMock) as mock_set,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_in()
|
|
|
coordinator_with_locks.cancel_mode_sync()
|
|
|
|
|
|
- mock_set.assert_not_awaited()
|
|
|
+ assert not any(
|
|
|
+ c.args[:2] == ("zlock_slots", "set_code") for c in mock_call.await_args_list
|
|
|
+ )
|
|
|
|
|
|
|
|
|
async def test_check_in_skips_lock_codes_when_use_zwave_off(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
@@ -969,16 +981,18 @@ async def test_check_in_skips_lock_codes_when_use_zwave_off(hass: HomeAssistant,
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=False),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode", new_callable=AsyncMock) as mock_set,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_in()
|
|
|
coordinator_with_locks.cancel_mode_sync()
|
|
|
|
|
|
- mock_set.assert_not_awaited()
|
|
|
+ assert not any(
|
|
|
+ c.args[:1] == ("zlock_slots",) for c in mock_call.await_args_list
|
|
|
+ )
|
|
|
|
|
|
|
|
|
async def test_check_in_skips_lock_codes_when_no_locks_configured(hass: HomeAssistant, coordinator: RoomCalCoordinator):
|
|
|
- # coordinator fixture has no CONF_ZWAVE_LOCKS in options
|
|
|
+ # coordinator fixture has no CONF_ZLOCK_ENTRIES in options
|
|
|
await coordinator.store.async_set(STORE_NEXT, _ZWAVE_RES)
|
|
|
coordinator._room_state_switch = None
|
|
|
|
|
|
@@ -986,15 +1000,17 @@ async def test_check_in_skips_lock_codes_when_no_locks_configured(hass: HomeAssi
|
|
|
patch.object(coordinator, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator, "_is_use_zwave_on", return_value=True),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode", new_callable=AsyncMock) as mock_set,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator._async_do_check_in()
|
|
|
coordinator.cancel_mode_sync()
|
|
|
|
|
|
- mock_set.assert_not_awaited()
|
|
|
+ assert not any(
|
|
|
+ c.args[:1] == ("zlock_slots",) for c in mock_call.await_args_list
|
|
|
+ )
|
|
|
|
|
|
|
|
|
-async def test_check_in_lock_error_still_activates_guest_mode(coordinator_with_locks: RoomCalCoordinator):
|
|
|
+async def test_check_in_lock_error_still_activates_guest_mode(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
await coordinator_with_locks.store.async_set(STORE_NEXT, _ZWAVE_RES)
|
|
|
mock_switch = MagicMock()
|
|
|
mock_switch.async_turn_on = AsyncMock()
|
|
|
@@ -1004,10 +1020,7 @@ async def test_check_in_lock_error_still_activates_guest_mode(coordinator_with_l
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=True),
|
|
|
patch("custom_components.room_cal_ha.coordinator.dt_util.now", return_value=_AT_CHECK_IN),
|
|
|
- patch(
|
|
|
- "custom_components.room_cal_ha.zwave_lock.async_set_lock_usercode",
|
|
|
- side_effect=HomeAssistantError("lock offline"),
|
|
|
- ),
|
|
|
+ patch.object(hass.services, "async_call", side_effect=HomeAssistantError("lock offline")),
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_in()
|
|
|
coordinator_with_locks.cancel_mode_sync()
|
|
|
@@ -1019,7 +1032,7 @@ async def test_check_in_lock_error_still_activates_guest_mode(coordinator_with_l
|
|
|
# Check-out Z-Wave lock behavior
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
-async def test_check_out_clears_lock_codes(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
+async def test_check_out_disables_lock_slot(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
await coordinator_with_locks.store.async_set(STORE_CURRENT, _ZWAVE_RES)
|
|
|
mock_switch = MagicMock()
|
|
|
mock_switch.async_turn_off = AsyncMock()
|
|
|
@@ -1028,29 +1041,31 @@ async def test_check_out_clears_lock_codes(hass: HomeAssistant, coordinator_with
|
|
|
with (
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=True),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_clear_lock_usercode", new_callable=AsyncMock) as mock_clear,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_out()
|
|
|
|
|
|
- mock_clear.assert_awaited_once_with(hass, "lock.front_door", 5)
|
|
|
+ mock_call.assert_awaited_once_with("zlock_slots", "set_slot_enabled", {"lock_entity_id": "lock.front_door", "slot": 5, "enabled": False}, blocking=True)
|
|
|
mock_switch.async_turn_off.assert_awaited_once()
|
|
|
|
|
|
|
|
|
-async def test_check_out_skips_lock_codes_when_use_zwave_off(coordinator_with_locks: RoomCalCoordinator):
|
|
|
+async def test_check_out_skips_lock_slot_when_use_zwave_off(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
await coordinator_with_locks.store.async_set(STORE_CURRENT, _ZWAVE_RES)
|
|
|
coordinator_with_locks._room_state_switch = None
|
|
|
|
|
|
with (
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=False),
|
|
|
- patch("custom_components.room_cal_ha.zwave_lock.async_clear_lock_usercode", new_callable=AsyncMock) as mock_clear,
|
|
|
+ patch.object(hass.services, "async_call", new_callable=AsyncMock) as mock_call,
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_out()
|
|
|
|
|
|
- mock_clear.assert_not_awaited()
|
|
|
+ assert not any(
|
|
|
+ c.args[:1] == ("zlock_slots",) for c in mock_call.await_args_list
|
|
|
+ )
|
|
|
|
|
|
|
|
|
-async def test_check_out_lock_error_still_deactivates_guest_mode(coordinator_with_locks: RoomCalCoordinator):
|
|
|
+async def test_check_out_lock_error_still_deactivates_guest_mode(hass: HomeAssistant, coordinator_with_locks: RoomCalCoordinator):
|
|
|
await coordinator_with_locks.store.async_set(STORE_CURRENT, _ZWAVE_RES)
|
|
|
mock_switch = MagicMock()
|
|
|
mock_switch.async_turn_off = AsyncMock()
|
|
|
@@ -1059,10 +1074,7 @@ async def test_check_out_lock_error_still_deactivates_guest_mode(coordinator_wit
|
|
|
with (
|
|
|
patch.object(coordinator_with_locks, "_is_mode_sync_on", return_value=True),
|
|
|
patch.object(coordinator_with_locks, "_is_use_zwave_on", return_value=True),
|
|
|
- patch(
|
|
|
- "custom_components.room_cal_ha.zwave_lock.async_clear_lock_usercode",
|
|
|
- side_effect=HomeAssistantError("lock offline"),
|
|
|
- ),
|
|
|
+ patch.object(hass.services, "async_call", side_effect=HomeAssistantError("lock offline")),
|
|
|
):
|
|
|
await coordinator_with_locks._async_do_check_out()
|
|
|
|