Use entry.runtime_data for caldav (#128278)

This commit is contained in:
Sid 2024-10-13 13:09:20 +02:00 committed by GitHub
parent 886399284b
commit c4ff3f731b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 15 deletions

View file

@ -17,7 +17,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from .const import DOMAIN
type CalDavConfigEntry = ConfigEntry[caldav.DAVClient]
_LOGGER = logging.getLogger(__name__)
@ -25,10 +25,8 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS: list[Platform] = [Platform.CALENDAR, Platform.TODO]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: CalDavConfigEntry) -> bool:
"""Set up CalDAV from a config entry."""
hass.data.setdefault(DOMAIN, {})
client = caldav.DAVClient(
entry.data[CONF_URL],
username=entry.data[CONF_USERNAME],
@ -50,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except DAVError as err:
raise ConfigEntryNotReady("CalDAV client error") from err
hass.data[DOMAIN][entry.entry_id] = client
entry.runtime_data = client
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View file

@ -15,7 +15,6 @@ from homeassistant.components.calendar import (
CalendarEvent,
is_offset_reached,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
@ -30,8 +29,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import CalDavConfigEntry
from .api import async_get_calendars
from .const import DOMAIN
from .coordinator import CalDavUpdateCoordinator
_LOGGER = logging.getLogger(__name__)
@ -141,12 +140,11 @@ async def async_setup_platform(
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: CalDavConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the CalDav calendar platform for a config entry."""
client: caldav.DAVClient = hass.data[DOMAIN][entry.entry_id]
calendars = await async_get_calendars(hass, client, SUPPORTED_COMPONENT)
calendars = await async_get_calendars(hass, entry.runtime_data, SUPPORTED_COMPONENT)
async_add_entities(
(
WebDavCalendarEntity(

View file

@ -18,14 +18,13 @@ from homeassistant.components.todo import (
TodoListEntity,
TodoListEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import dt as dt_util
from . import CalDavConfigEntry
from .api import async_get_calendars, get_attr_value
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
@ -46,12 +45,11 @@ TODO_STATUS_MAP_INV: dict[TodoItemStatus, str] = {
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
entry: CalDavConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the CalDav todo platform for a config entry."""
client: caldav.DAVClient = hass.data[DOMAIN][entry.entry_id]
calendars = await async_get_calendars(hass, client, SUPPORTED_COMPONENT)
calendars = await async_get_calendars(hass, entry.runtime_data, SUPPORTED_COMPONENT)
async_add_entities(
(
WebDavTodoListEntity(