mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Omit declined Google Calendar events (#128900)
* Omit decline Google Calendar events * move comment to top of function and update * Apply suggestions from code review * import ResponseStatus
This commit is contained in:
parent
b1470fd9b8
commit
9bf0cbd659
@ -10,7 +10,14 @@ from typing import Any, cast
|
||||
|
||||
from gcal_sync.api import Range, SyncEventsRequest
|
||||
from gcal_sync.exceptions import ApiException
|
||||
from gcal_sync.model import AccessRole, Calendar, DateOrDatetime, Event, EventTypeEnum
|
||||
from gcal_sync.model import (
|
||||
AccessRole,
|
||||
Calendar,
|
||||
DateOrDatetime,
|
||||
Event,
|
||||
EventTypeEnum,
|
||||
ResponseStatus,
|
||||
)
|
||||
from gcal_sync.store import ScopedCalendarStore
|
||||
from gcal_sync.sync import CalendarEventSyncManager
|
||||
|
||||
@ -367,7 +374,14 @@ class GoogleCalendarEntity(
|
||||
return event
|
||||
|
||||
def _event_filter(self, event: Event) -> bool:
|
||||
"""Return True if the event is visible."""
|
||||
"""Return True if the event is visible and not declined."""
|
||||
|
||||
if any(
|
||||
attendee.is_self and attendee.response_status == ResponseStatus.DECLINED
|
||||
for attendee in event.attendees
|
||||
):
|
||||
return False
|
||||
|
||||
if event.event_type == EventTypeEnum.WORKING_LOCATION:
|
||||
return self.entity_description.working_location
|
||||
if self._ignore_availability:
|
||||
|
@ -572,6 +572,62 @@ async def test_opaque_event(
|
||||
assert state.state == (STATE_ON if expect_visible_event else STATE_OFF)
|
||||
|
||||
|
||||
async def test_declined_event(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_calendars_yaml,
|
||||
mock_events_list_items,
|
||||
component_setup,
|
||||
) -> None:
|
||||
"""Test querying the API and fetching events from the server."""
|
||||
event = {
|
||||
**TEST_EVENT,
|
||||
**upcoming(),
|
||||
"attendees": [
|
||||
{
|
||||
"self": "True",
|
||||
"responseStatus": "declined",
|
||||
}
|
||||
],
|
||||
}
|
||||
mock_events_list_items([event])
|
||||
assert await component_setup()
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get(upcoming_event_url(TEST_YAML_ENTITY))
|
||||
assert response.status == HTTPStatus.OK
|
||||
events = await response.json()
|
||||
assert len(events) == 0
|
||||
|
||||
|
||||
async def test_attending_event(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_calendars_yaml,
|
||||
mock_events_list_items,
|
||||
component_setup,
|
||||
) -> None:
|
||||
"""Test querying the API and fetching events from the server."""
|
||||
event = {
|
||||
**TEST_EVENT,
|
||||
**upcoming(),
|
||||
"attendees": [
|
||||
{
|
||||
"self": "True",
|
||||
"responseStatus": "accepted",
|
||||
}
|
||||
],
|
||||
}
|
||||
mock_events_list_items([event])
|
||||
assert await component_setup()
|
||||
|
||||
client = await hass_client()
|
||||
response = await client.get(upcoming_event_url(TEST_YAML_ENTITY))
|
||||
assert response.status == HTTPStatus.OK
|
||||
events = await response.json()
|
||||
assert len(events) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_test_setup", [None])
|
||||
async def test_scan_calendar_error(
|
||||
hass: HomeAssistant,
|
||||
|
Loading…
x
Reference in New Issue
Block a user