8000 Revert google calendar back to old API for free/busy readers by allenporter · Pull Request #81894 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Revert google calendar back to old API for free/busy readers #81894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions homeassistant/components/google/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from gcal_sync.api import GoogleCalendarService, ListEventsRequest, SyncEventsRequest
from gcal_sync.exceptions import ApiException
from gcal_sync.model import DateOrDatetime, Event
from gcal_sync.model import AccessRole, DateOrDatetime, Event
from gcal_sync.store import ScopedCalendarStore
from gcal_sync.sync import CalendarEventSyncManager
from gcal_sync.timeline import Timeline
Expand Down Expand Up @@ -198,7 +198,13 @@ async def async_setup_entry(
entity_entry.entity_id,
)
coordinator: CalendarSyncUpdateCoordinator | CalendarQueryUpdateCoordinator
if search := data.get(CONF_SEARCH):
# Prefer calendar sync down of resources when possible. However, sync does not work
# for search. Also free-busy calendars denormalize recurring events as individual
# events which is not efficient for sync
if (
search := data.get(CONF_SEARCH)
or calendar_item.access_role == AccessRole.FREE_BUSY_READER
):
coordinator = CalendarQueryUpdateCoordinator(
hass,
calendar_service,
Expand Down
14 changes: 11 additions & 3 deletions tests/components/google/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"id": CALENDAR_ID,
"etag": '"3584134138943410"',
"timeZone": "UTC",
"accessRole": "reader",
"foregroundColor": "#000000",
"selected": True,
"kind": "calendar#calendarListEntry",
Expand All @@ -62,10 +61,19 @@
CLIENT_SECRET = "client-secret"


@pytest.fixture(name="calendar_access_role")
def test_calendar_access_role() -> str:
"""Default access role to use for test_api_calendar in tests."""
return "reader"


@pytest.fixture
def test_api_calendar():
def test_api_calendar(calendar_access_role: str):
"""Return a test calendar object used in API responses."""
return TEST_API_CALENDAR
return {
**TEST_API_CALENDAR,
"accessRole": calendar_access_role,
}


@pytest.fixture
Expand Down
21 changes: 16 additions & 5 deletions tests/components/google/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
}


@pytest.fixture(
autouse=True, scope="module", params=["reader", "owner", "freeBusyReader"]
)
def calendar_access_role(request) -> str:
"""Fixture to exercise access roles in tests."""
return request.param


@pytest.fixture(autouse=True)
def mock_test_setup(
test_api_calendar,
Expand Down Expand Up @@ -720,12 +728,15 @@ async def test_invalid_unique_id_cleanup(


@pytest.mark.parametrize(
"time_zone,event_order",
"time_zone,event_order,calendar_access_role",
# This only tests the reader role to force testing against the local
# database filtering based on start/end time. (free busy reader would
# just use the API response which this test is not exercising)
[
("America/Los_Angeles", ["One", "Two", "All Day Event"]),
("America/Regina", ["One", "Two", "All Day Event"]),
("UTC", ["One", "All Day Event", "Two"]),
("Asia/Tokyo", ["All Day Event", "One", "Two"]),
("America/Los_Angeles", ["One", "Two", "All Day Event"], "reader"),
("America/Regina", ["One", "Two", "All Day Event"], "reader"),
("UTC", ["One", "All Day Event", "Two"], "reader"),
("Asia/Tokyo", ["All Day Event", "One", "Two"], "reader"),
],
)
async def test_all_day_iter_order(
Expand Down
0