mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Simplify google calendar new calendar tracking (#67772)
* Simplify google calendar new calendar tracking * Remove application of CONFIG_SCHEMA
This commit is contained in:
parent
2957f4ce85
commit
74c339eb7b
@ -33,7 +33,6 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity import generate_entity_id
|
from homeassistant.helpers.entity import generate_entity_id
|
||||||
from homeassistant.helpers.event import track_utc_time_change
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import convert
|
|
||||||
|
|
||||||
from .api import GoogleCalendarService
|
from .api import GoogleCalendarService
|
||||||
|
|
||||||
@ -51,7 +50,6 @@ CONF_IGNORE_AVAILABILITY = "ignore_availability"
|
|||||||
CONF_MAX_RESULTS = "max_results"
|
CONF_MAX_RESULTS = "max_results"
|
||||||
CONF_CALENDAR_ACCESS = "calendar_access"
|
CONF_CALENDAR_ACCESS = "calendar_access"
|
||||||
|
|
||||||
DEFAULT_CONF_TRACK_NEW = True
|
|
||||||
DEFAULT_CONF_OFFSET = "!!"
|
DEFAULT_CONF_OFFSET = "!!"
|
||||||
|
|
||||||
EVENT_CALENDAR_ID = "calendar_id"
|
EVENT_CALENDAR_ID = "calendar_id"
|
||||||
@ -106,7 +104,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
vol.Required(CONF_CLIENT_ID): cv.string,
|
vol.Required(CONF_CLIENT_ID): cv.string,
|
||||||
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
||||||
vol.Optional(CONF_TRACK_NEW): cv.boolean,
|
vol.Optional(CONF_TRACK_NEW, default=True): cv.boolean,
|
||||||
vol.Optional(CONF_CALENDAR_ACCESS, default="read_write"): cv.enum(
|
vol.Optional(CONF_CALENDAR_ACCESS, default="read_write"): cv.enum(
|
||||||
FeatureAccess
|
FeatureAccess
|
||||||
),
|
),
|
||||||
@ -279,7 +277,6 @@ def setup_services(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_config: ConfigType,
|
hass_config: ConfigType,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
track_new_found_calendars: bool,
|
|
||||||
calendar_service: GoogleCalendarService,
|
calendar_service: GoogleCalendarService,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the service listeners."""
|
"""Set up the service listeners."""
|
||||||
@ -306,7 +303,7 @@ def setup_services(
|
|||||||
"""Scan for new calendars."""
|
"""Scan for new calendars."""
|
||||||
calendars = calendar_service.list_calendars()
|
calendars = calendar_service.list_calendars()
|
||||||
for calendar in calendars:
|
for calendar in calendars:
|
||||||
calendar["track"] = track_new_found_calendars
|
calendar[CONF_TRACK] = config[CONF_TRACK_NEW]
|
||||||
hass.services.call(DOMAIN, SERVICE_FOUND_CALENDARS, calendar)
|
hass.services.call(DOMAIN, SERVICE_FOUND_CALENDARS, calendar)
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_SCAN_CALENDARS, _scan_for_calendars)
|
hass.services.register(DOMAIN, SERVICE_SCAN_CALENDARS, _scan_for_calendars)
|
||||||
@ -371,13 +368,7 @@ def do_setup(hass: HomeAssistant, hass_config: ConfigType, config: ConfigType) -
|
|||||||
hass.data[DOMAIN][DATA_CALENDARS] = calendars
|
hass.data[DOMAIN][DATA_CALENDARS] = calendars
|
||||||
|
|
||||||
calendar_service = hass.data[DOMAIN][DATA_SERVICE]
|
calendar_service = hass.data[DOMAIN][DATA_SERVICE]
|
||||||
track_new_found_calendars = convert(
|
setup_services(hass, hass_config, config, calendar_service)
|
||||||
config.get(CONF_TRACK_NEW), bool, DEFAULT_CONF_TRACK_NEW
|
|
||||||
)
|
|
||||||
assert track_new_found_calendars is not None
|
|
||||||
setup_services(
|
|
||||||
hass, hass_config, config, track_new_found_calendars, calendar_service
|
|
||||||
)
|
|
||||||
|
|
||||||
for calendar in calendars.values():
|
for calendar in calendars.values():
|
||||||
discovery.load_platform(hass, Platform.CALENDAR, DOMAIN, calendar, hass_config)
|
discovery.load_platform(hass, Platform.CALENDAR, DOMAIN, calendar, hass_config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user