"""Support for Renault devices.""" import aiohttp from renault_api.exceptions import NotAuthenticatedException from renault_api.gigya.exceptions import GigyaException from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, PLATFORMS, RenaultConfigurationKeys from .renault_hub import RenaultHub from .services import async_setup_services CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) type RenaultConfigEntry = ConfigEntry[RenaultHub] async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Renault component.""" async_setup_services(hass) return True async def async_setup_entry( hass: HomeAssistant, config_entry: RenaultConfigEntry ) -> bool: """Load a config entry.""" renault_hub = RenaultHub(hass, config_entry.data[RenaultConfigurationKeys.LOCALE]) try: await renault_hub.async_initialise(config_entry) except NotAuthenticatedException as exc: raise ConfigEntryAuthFailed from exc except (aiohttp.ClientError, GigyaException) as exc: raise ConfigEntryNotReady from exc config_entry.runtime_data = renault_hub await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) return True async def async_unload_entry( hass: HomeAssistant, config_entry: RenaultConfigEntry ) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS) async def async_remove_config_entry_device( hass: HomeAssistant, config_entry: RenaultConfigEntry, device_entry: dr.AnyDeviceEntry, ) -> bool: """Remove a config entry from a device.""" return not device_entry.identifiers.intersection( (DOMAIN, vin) for vin in config_entry.runtime_data.vehicles )