Add calendar event end trigger (#70372)
* Add calendar event end trigger * Rename start date to last_endtime * Rename now to last_endtime
This commit is contained in:
parent
9008a76bd4
commit
5ffaa70bb6
2 changed files with 81 additions and 20 deletions
|
@ -19,7 +19,7 @@ import pytest
|
|||
|
||||
from homeassistant.components import calendar
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.calendar.trigger import EVENT_START
|
||||
from homeassistant.components.calendar.trigger import EVENT_END, EVENT_START
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -189,10 +189,38 @@ async def test_event_start_trigger(hass, calls, fake_schedule):
|
|||
]
|
||||
|
||||
|
||||
async def test_event_end_trigger(hass, calls, fake_schedule):
|
||||
"""Test the a calendar trigger based on end time."""
|
||||
event_data = fake_schedule.create_event(
|
||||
start=datetime.datetime.fromisoformat("2022-04-19 11:00:00+00:00"),
|
||||
end=datetime.datetime.fromisoformat("2022-04-19 12:00:00+00:00"),
|
||||
)
|
||||
await create_automation(hass, EVENT_END)
|
||||
|
||||
# Event started, nothing should fire yet
|
||||
await fake_schedule.fire_until(
|
||||
datetime.datetime.fromisoformat("2022-04-19 11:10:00+00:00")
|
||||
)
|
||||
assert len(calls()) == 0
|
||||
|
||||
# Event ends
|
||||
await fake_schedule.fire_until(
|
||||
datetime.datetime.fromisoformat("2022-04-19 12:10:00+00:00")
|
||||
)
|
||||
assert calls() == [
|
||||
{
|
||||
"platform": "calendar",
|
||||
"event": EVENT_END,
|
||||
"calendar_event": event_data,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
async def test_calendar_trigger_with_no_events(hass, calls, fake_schedule):
|
||||
"""Test a calendar trigger setup with no events."""
|
||||
|
||||
await create_automation(hass, EVENT_START)
|
||||
await create_automation(hass, EVENT_END)
|
||||
|
||||
# No calls, at arbitrary times
|
||||
await fake_schedule.fire_until(
|
||||
|
@ -201,7 +229,7 @@ async def test_calendar_trigger_with_no_events(hass, calls, fake_schedule):
|
|||
assert len(calls()) == 0
|
||||
|
||||
|
||||
async def test_multiple_events(hass, calls, fake_schedule):
|
||||
async def test_multiple_start_events(hass, calls, fake_schedule):
|
||||
"""Test that a trigger fires for multiple events."""
|
||||
|
||||
event_data1 = fake_schedule.create_event(
|
||||
|
@ -231,6 +259,36 @@ async def test_multiple_events(hass, calls, fake_schedule):
|
|||
]
|
||||
|
||||
|
||||
async def test_multiple_end_events(hass, calls, fake_schedule):
|
||||
"""Test that a trigger fires for multiple events."""
|
||||
|
||||
event_data1 = fake_schedule.create_event(
|
||||
start=datetime.datetime.fromisoformat("2022-04-19 10:45:00+00:00"),
|
||||
end=datetime.datetime.fromisoformat("2022-04-19 11:00:00+00:00"),
|
||||
)
|
||||
event_data2 = fake_schedule.create_event(
|
||||
start=datetime.datetime.fromisoformat("2022-04-19 11:00:00+00:00"),
|
||||
end=datetime.datetime.fromisoformat("2022-04-19 11:15:00+00:00"),
|
||||
)
|
||||
await create_automation(hass, EVENT_END)
|
||||
|
||||
await fake_schedule.fire_until(
|
||||
datetime.datetime.fromisoformat("2022-04-19 11:30:00+00:00")
|
||||
)
|
||||
assert calls() == [
|
||||
{
|
||||
"platform": "calendar",
|
||||
"event": EVENT_END,
|
||||
"calendar_event": event_data1,
|
||||
},
|
||||
{
|
||||
"platform": "calendar",
|
||||
"event": EVENT_END,
|
||||
"calendar_event": event_data2,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def test_multiple_events_sharing_start_time(hass, calls, fake_schedule):
|
||||
"""Test that a trigger fires for every event sharing a start time."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue