mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Improve google
calendar generic typing (#84633)
This commit is contained in:
parent
511f3335a1
commit
b8f83074ce
@ -6,7 +6,7 @@ import asyncio
|
|||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any, Union, cast
|
||||||
|
|
||||||
from gcal_sync.api import (
|
from gcal_sync.api import (
|
||||||
GoogleCalendarService,
|
GoogleCalendarService,
|
||||||
@ -384,7 +384,12 @@ class CalendarQueryUpdateCoordinator(DataUpdateCoordinator[list[Event]]):
|
|||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
|
|
||||||
class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
class GoogleCalendarEntity(
|
||||||
|
CoordinatorEntity[
|
||||||
|
Union[CalendarSyncUpdateCoordinator, CalendarQueryUpdateCoordinator]
|
||||||
|
],
|
||||||
|
CalendarEntity,
|
||||||
|
):
|
||||||
"""A calendar event entity."""
|
"""A calendar event entity."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
@ -401,7 +406,6 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Create the Calendar event device."""
|
"""Create the Calendar event device."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.coordinator = coordinator
|
|
||||||
self.calendar_id = calendar_id
|
self.calendar_id = calendar_id
|
||||||
self._ignore_availability: bool = data.get(CONF_IGNORE_AVAILABILITY, False)
|
self._ignore_availability: bool = data.get(CONF_IGNORE_AVAILABILITY, False)
|
||||||
self._event: CalendarEvent | None = None
|
self._event: CalendarEvent | None = None
|
||||||
@ -535,7 +539,9 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
|||||||
if rrule := kwargs.get(EVENT_RRULE):
|
if rrule := kwargs.get(EVENT_RRULE):
|
||||||
event.recurrence = [f"{RRULE_PREFIX}{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()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_delete_event(
|
async def async_delete_event(
|
||||||
@ -548,7 +554,9 @@ class GoogleCalendarEntity(CoordinatorEntity, CalendarEntity):
|
|||||||
range_value: Range = Range.NONE
|
range_value: Range = Range.NONE
|
||||||
if recurrence_range == Range.THIS_AND_FUTURE:
|
if recurrence_range == Range.THIS_AND_FUTURE:
|
||||||
range_value = 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,
|
ical_uuid=uid,
|
||||||
event_id=recurrence_id,
|
event_id=recurrence_id,
|
||||||
recurrence_range=range_value,
|
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")
|
raise ValueError("Missing required fields to set start or end date/datetime")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await entity.coordinator.sync.api.async_create_event(
|
await cast(
|
||||||
|
CalendarSyncUpdateCoordinator, entity.coordinator
|
||||||
|
).sync.api.async_create_event(
|
||||||
entity.calendar_id,
|
entity.calendar_id,
|
||||||
Event(
|
Event(
|
||||||
summary=call.data[EVENT_SUMMARY],
|
summary=call.data[EVENT_SUMMARY],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user