Improve google calendar generic typing (#84633)

This commit is contained in:
Marc Mueller 2022-12-27 21:21:16 +01:00 committed by GitHub
parent 511f3335a1
commit b8f83074ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@ import asyncio
from collections.abc import Iterable
from datetime import datetime, timedelta
import logging
from typing import Any
from typing import Any, Union, cast
from gcal_sync.api import (
GoogleCalendarService,
@ -384,7 +384,12 @@ class CalendarQueryUpdateCoordinator(DataUpdateCoordinator[list[Event]]):
return self.data
class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
class GoogleCalendarEntity(
CoordinatorEntity[
Union[CalendarSyncUpdateCoordinator, CalendarQueryUpdateCoordinator]
],
CalendarEntity,
):
"""A calendar event entity."""
_attr_has_entity_name = True
@ -401,7 +406,6 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
) -> None:
"""Create the Calendar event device."""
super().__init__(coordinator)
self.coordinator = coordinator
self.calendar_id = calendar_id
self._ignore_availability: bool = data.get(CONF_IGNORE_AVAILABILITY, False)
self._event: CalendarEvent | None = None
@ -535,7 +539,9 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
if rrule := kwargs.get(EVENT_RRULE):
event.recurrence = [f"{RRULE_PREFIX}{rrule}"]
await self.coordinator.sync.store_service.async_add_event(event)
await cast(
CalendarSyncUpdateCoordinator, self.coordinator
).sync.store_service.async_add_event(event)
await self.coordinator.async_refresh()
async def async_delete_event(
@ -548,7 +554,9 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
range_value: Range = Range.NONE
if recurrence_range == Range.THIS_AND_FUTURE:
range_value = Range.THIS_AND_FUTURE
await self.coordinator.sync.store_service.async_delete_event(
await cast(
CalendarSyncUpdateCoordinator, self.coordinator
).sync.store_service.async_delete_event(
ical_uuid=uid,
event_id=recurrence_id,
recurrence_range=range_value,
@ -612,7 +620,9 @@ async def async_create_event(entity: GoogleCalendarEntity, call: ServiceCall) ->
raise ValueError("Missing required fields to set start or end date/datetime")
try:
await entity.coordinator.sync.api.async_create_event(
await cast(
CalendarSyncUpdateCoordinator, entity.coordinator
).sync.api.async_create_event(
entity.calendar_id,
Event(
summary=call.data[EVENT_SUMMARY],