mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Use entry.runtime_data for caldav (#128278)
This commit is contained in:
parent
886399284b
commit
c4ff3f731b
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
|
|
||||||
from .const import DOMAIN
|
type CalDavConfigEntry = ConfigEntry[caldav.DAVClient]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -25,10 +25,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
PLATFORMS: list[Platform] = [Platform.CALENDAR, Platform.TODO]
|
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."""
|
"""Set up CalDAV from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
|
|
||||||
client = caldav.DAVClient(
|
client = caldav.DAVClient(
|
||||||
entry.data[CONF_URL],
|
entry.data[CONF_URL],
|
||||||
username=entry.data[CONF_USERNAME],
|
username=entry.data[CONF_USERNAME],
|
||||||
@ -50,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except DAVError as err:
|
except DAVError as err:
|
||||||
raise ConfigEntryNotReady("CalDAV client error") from 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)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ from homeassistant.components.calendar import (
|
|||||||
CalendarEvent,
|
CalendarEvent,
|
||||||
is_offset_reached,
|
is_offset_reached,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
@ -30,8 +29,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import CalDavConfigEntry
|
||||||
from .api import async_get_calendars
|
from .api import async_get_calendars
|
||||||
from .const import DOMAIN
|
|
||||||
from .coordinator import CalDavUpdateCoordinator
|
from .coordinator import CalDavUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -141,12 +140,11 @@ async def async_setup_platform(
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: CalDavConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the CalDav calendar platform for a config entry."""
|
"""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, entry.runtime_data, SUPPORTED_COMPONENT)
|
||||||
calendars = await async_get_calendars(hass, client, SUPPORTED_COMPONENT)
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
(
|
(
|
||||||
WebDavCalendarEntity(
|
WebDavCalendarEntity(
|
||||||
|
@ -18,14 +18,13 @@ from homeassistant.components.todo import (
|
|||||||
TodoListEntity,
|
TodoListEntity,
|
||||||
TodoListEntityFeature,
|
TodoListEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from . import CalDavConfigEntry
|
||||||
from .api import async_get_calendars, get_attr_value
|
from .api import async_get_calendars, get_attr_value
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -46,12 +45,11 @@ TODO_STATUS_MAP_INV: dict[TodoItemStatus, str] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: CalDavConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the CalDav todo platform for a config entry."""
|
"""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, entry.runtime_data, SUPPORTED_COMPONENT)
|
||||||
calendars = await async_get_calendars(hass, client, SUPPORTED_COMPONENT)
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
(
|
(
|
||||||
WebDavTodoListEntity(
|
WebDavTodoListEntity(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user