mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Set config_entry explicitly in caldav coordinator (#129424)
This commit is contained in:
parent
6323a078e1
commit
b8f2583bc3
@ -109,6 +109,7 @@ async def async_setup_platform(
|
|||||||
entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
||||||
coordinator = CalDavUpdateCoordinator(
|
coordinator = CalDavUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
None,
|
||||||
calendar=calendar,
|
calendar=calendar,
|
||||||
days=days,
|
days=days,
|
||||||
include_all_day=True,
|
include_all_day=True,
|
||||||
@ -126,6 +127,7 @@ async def async_setup_platform(
|
|||||||
entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
||||||
coordinator = CalDavUpdateCoordinator(
|
coordinator = CalDavUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
None,
|
||||||
calendar=calendar,
|
calendar=calendar,
|
||||||
days=days,
|
days=days,
|
||||||
include_all_day=False,
|
include_all_day=False,
|
||||||
@ -152,6 +154,7 @@ async def async_setup_entry(
|
|||||||
async_generate_entity_id(ENTITY_ID_FORMAT, calendar.name, hass=hass),
|
async_generate_entity_id(ENTITY_ID_FORMAT, calendar.name, hass=hass),
|
||||||
CalDavUpdateCoordinator(
|
CalDavUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
entry,
|
||||||
calendar=calendar,
|
calendar=calendar,
|
||||||
days=CONFIG_ENTRY_DEFAULT_DAYS,
|
days=CONFIG_ENTRY_DEFAULT_DAYS,
|
||||||
include_all_day=True,
|
include_all_day=True,
|
||||||
@ -204,7 +207,8 @@ class WebDavCalendarEntity(CoordinatorEntity[CalDavUpdateCoordinator], CalendarE
|
|||||||
if self._supports_offset:
|
if self._supports_offset:
|
||||||
self._attr_extra_state_attributes = {
|
self._attr_extra_state_attributes = {
|
||||||
"offset_reached": is_offset_reached(
|
"offset_reached": is_offset_reached(
|
||||||
self._event.start_datetime_local, self.coordinator.offset
|
self._event.start_datetime_local,
|
||||||
|
self.coordinator.offset, # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
if self._event
|
if self._event
|
||||||
else False
|
else False
|
||||||
|
@ -6,6 +6,9 @@ from datetime import date, datetime, time, timedelta
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import caldav
|
||||||
|
|
||||||
from homeassistant.components.calendar import CalendarEvent, extract_offset
|
from homeassistant.components.calendar import CalendarEvent, extract_offset
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -14,6 +17,9 @@ from homeassistant.util import dt as dt_util
|
|||||||
|
|
||||||
from .api import get_attr_value
|
from .api import get_attr_value
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import CalDavConfigEntry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
||||||
@ -23,11 +29,20 @@ OFFSET = "!!"
|
|||||||
class CalDavUpdateCoordinator(DataUpdateCoordinator[CalendarEvent | None]):
|
class CalDavUpdateCoordinator(DataUpdateCoordinator[CalendarEvent | None]):
|
||||||
"""Class to utilize the calendar dav client object to get next event."""
|
"""Class to utilize the calendar dav client object to get next event."""
|
||||||
|
|
||||||
def __init__(self, hass, calendar, days, include_all_day, search):
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: CalDavConfigEntry | None,
|
||||||
|
calendar: caldav.Calendar,
|
||||||
|
days: int,
|
||||||
|
include_all_day: bool,
|
||||||
|
search: str | None,
|
||||||
|
) -> None:
|
||||||
"""Set up how we are going to search the WebDav calendar."""
|
"""Set up how we are going to search the WebDav calendar."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=entry,
|
||||||
name=f"CalDAV {calendar.name}",
|
name=f"CalDAV {calendar.name}",
|
||||||
update_interval=MIN_TIME_BETWEEN_UPDATES,
|
update_interval=MIN_TIME_BETWEEN_UPDATES,
|
||||||
)
|
)
|
||||||
@ -35,7 +50,7 @@ class CalDavUpdateCoordinator(DataUpdateCoordinator[CalendarEvent | None]):
|
|||||||
self.days = days
|
self.days = days
|
||||||
self.include_all_day = include_all_day
|
self.include_all_day = include_all_day
|
||||||
self.search = search
|
self.search = search
|
||||||
self.offset = None
|
self.offset: timedelta | None = None
|
||||||
|
|
||||||
async def async_get_events(
|
async def async_get_events(
|
||||||
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
|
self, hass: HomeAssistant, start_date: datetime, end_date: datetime
|
||||||
@ -109,7 +124,7 @@ class CalDavUpdateCoordinator(DataUpdateCoordinator[CalendarEvent | None]):
|
|||||||
_start_of_tomorrow = start_of_tomorrow
|
_start_of_tomorrow = start_of_tomorrow
|
||||||
if _start_of_today <= start_dt < _start_of_tomorrow:
|
if _start_of_today <= start_dt < _start_of_tomorrow:
|
||||||
new_event = event.copy()
|
new_event = event.copy()
|
||||||
new_vevent = new_event.instance.vevent
|
new_vevent = new_event.instance.vevent # type: ignore[attr-defined]
|
||||||
if hasattr(new_vevent, "dtend"):
|
if hasattr(new_vevent, "dtend"):
|
||||||
dur = new_vevent.dtend.value - new_vevent.dtstart.value
|
dur = new_vevent.dtend.value - new_vevent.dtstart.value
|
||||||
new_vevent.dtend.value = start_dt + dur
|
new_vevent.dtend.value = start_dt + dur
|
||||||
|
Loading…
x
Reference in New Issue
Block a user