1 """Support for Google Mail."""
3 from __future__
import annotations
11 async_get_config_entry_implementation,
15 from .api
import AsyncConfigEntryAuth
16 from .const
import DATA_AUTH, DATA_HASS_CONFIG, DOMAIN
17 from .services
import async_setup_services
19 type GoogleMailConfigEntry = ConfigEntry[AsyncConfigEntryAuth]
21 PLATFORMS = [Platform.NOTIFY, Platform.SENSOR]
23 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
26 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
27 """Set up the Google Mail platform."""
28 hass.data.setdefault(DOMAIN, {})[DATA_HASS_CONFIG] = config
34 """Set up Google Mail from a config entry."""
38 await auth.check_and_refresh_token()
39 entry.runtime_data = auth
41 hass.async_create_task(
42 discovery.async_load_platform(
46 {DATA_AUTH: auth, CONF_NAME: entry.title},
47 hass.data[DOMAIN][DATA_HASS_CONFIG],
51 await hass.config_entries.async_forward_entry_setups(
52 entry, [platform
for platform
in PLATFORMS
if platform != Platform.NOTIFY]
61 """Unload a config entry."""
64 for entry
in hass.config_entries.async_entries(DOMAIN)
65 if entry.state == ConfigEntryState.LOADED
67 if len(loaded_entries) == 1:
68 for service_name
in hass.services.async_services_for_domain(DOMAIN):
69 hass.services.async_remove(DOMAIN, service_name)
71 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, GoogleMailConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_setup_entry(HomeAssistant hass, GoogleMailConfigEntry entry)
None async_setup_services(HomeAssistant hass)
AbstractOAuth2Implementation async_get_config_entry_implementation(HomeAssistant hass, config_entries.ConfigEntry config_entry)