1 """Integration for Apple's WeatherKit API."""
3 from __future__
import annotations
5 from apple_weatherkit.client
import (
7 WeatherKitApiClientAuthenticationError,
8 WeatherKitApiClientError,
25 from .coordinator
import WeatherKitDataUpdateCoordinator
27 PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.WEATHER]
31 """Set up this integration using UI."""
32 hass.data.setdefault(DOMAIN, {})
35 client=WeatherKitApiClient(
36 key_id=entry.data[CONF_KEY_ID],
37 service_id=entry.data[CONF_SERVICE_ID],
38 team_id=entry.data[CONF_TEAM_ID],
39 key_pem=entry.data[CONF_KEY_PEM],
45 await coordinator.update_supported_data_sets()
46 except WeatherKitApiClientAuthenticationError
as ex:
47 LOGGER.error(
"Authentication error initializing integration: %s", ex)
49 except WeatherKitApiClientError
as ex:
50 raise ConfigEntryNotReady
from ex
52 await coordinator.async_config_entry_first_refresh()
53 hass.data[DOMAIN][entry.entry_id] = coordinator
55 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
60 """Handle removal of an entry."""
61 if unloaded := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
62 hass.data[DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)