|
|
@@ -13,7 +13,6 @@ from pytest_homeassistant_custom_component.common import MockConfigEntry
|
|
|
from custom_components.room_cal_ha.binary_sensor import ArrivedSensor, DepartedSensor
|
|
|
from custom_components.room_cal_ha.button import GuestArrivedButton, GuestDepartedButton
|
|
|
from custom_components.room_cal_ha.const import (
|
|
|
- CONF_GUEST_SCRIPT,
|
|
|
CONF_SYNC_MODE,
|
|
|
DOMAIN,
|
|
|
STORE_CURRENT,
|
|
|
@@ -254,59 +253,3 @@ async def test_flags_reset_on_checkout(coord: RoomCalCoordinator):
|
|
|
assert coord.data.current_arrived is False
|
|
|
|
|
|
|
|
|
-# ---------------------------------------------------------------------------
|
|
|
-# Script dispatch
|
|
|
-# ---------------------------------------------------------------------------
|
|
|
-
|
|
|
-async def test_set_arrived_dispatches_script(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_SYNC_MODE: SYNC_MODE_MANUAL, CONF_GUEST_SCRIPT: "script.guest_event"})
|
|
|
- c = RoomCalCoordinator(hass, entry)
|
|
|
- await c.async_setup()
|
|
|
- await c.async_refresh()
|
|
|
-
|
|
|
- with patch.object(c, "_async_run_guest_script", new=AsyncMock()) as mock_script:
|
|
|
- await c.async_set_arrived(True)
|
|
|
-
|
|
|
- mock_script.assert_awaited_once_with("arrived")
|
|
|
-
|
|
|
-
|
|
|
-async def test_set_departed_dispatches_script(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_SYNC_MODE: SYNC_MODE_MANUAL, CONF_GUEST_SCRIPT: "script.guest_event"})
|
|
|
- c = RoomCalCoordinator(hass, entry)
|
|
|
- await c.async_setup()
|
|
|
- await c.async_refresh()
|
|
|
-
|
|
|
- with patch.object(c, "_async_run_guest_script", new=AsyncMock()) as mock_script:
|
|
|
- await c.async_set_departed(True)
|
|
|
-
|
|
|
- mock_script.assert_awaited_once_with("departed")
|
|
|
-
|
|
|
-
|
|
|
-async def test_guest_script_includes_entry_id(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_SYNC_MODE: SYNC_MODE_MANUAL, CONF_GUEST_SCRIPT: "script.guest_event"})
|
|
|
- c = RoomCalCoordinator(hass, entry)
|
|
|
- await c.async_setup()
|
|
|
-
|
|
|
- with patch("homeassistant.core.ServiceRegistry.async_call", new=AsyncMock()) as mock_call:
|
|
|
- await c._async_run_guest_script("arrived")
|
|
|
-
|
|
|
- mock_call.assert_awaited_once()
|
|
|
- _domain, _service, data = mock_call.call_args.args # (domain, service, data)
|
|
|
- assert data["variables"]["event_type"] == "arrived"
|
|
|
- assert data["variables"]["entry_id"] == entry.entry_id
|
|
|
-
|
|
|
-
|
|
|
-async def test_no_script_dispatched_when_setting_false(hass: HomeAssistant):
|
|
|
- entry = _make_entry(hass, {CONF_SYNC_MODE: SYNC_MODE_MANUAL, CONF_GUEST_SCRIPT: "script.guest_event"})
|
|
|
- c = RoomCalCoordinator(hass, entry)
|
|
|
- await c.async_setup()
|
|
|
- await c.async_refresh()
|
|
|
-
|
|
|
- with patch.object(c, "_async_run_guest_script", new=AsyncMock()) as mock_script:
|
|
|
- await c.async_set_arrived(False)
|
|
|
- mock_script.assert_not_awaited()
|
|
|
-
|
|
|
-
|
|
|
-async def test_async_run_guest_script_no_op_when_not_configured(coord: RoomCalCoordinator):
|
|
|
- # coord has no CONF_GUEST_SCRIPT — should return early with no error
|
|
|
- await coord._async_run_guest_script("arrived")
|