2021-07-28 19:41:11 +00:00
|
|
|
"""Support for Renault devices."""
|
2024-03-08 18:15:59 +00:00
|
|
|
|
2021-07-28 19:41:11 +00:00
|
|
|
import aiohttp
|
2023-02-09 15:55:02 +00:00
|
|
|
from renault_api.gigya.exceptions import GigyaException
|
2021-07-28 19:41:11 +00:00
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-09-04 00:17:24 +00:00
|
|
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
2024-04-30 15:10:40 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2021-07-28 19:41:11 +00:00
|
|
|
|
|
|
|
from .const import CONF_LOCALE, DOMAIN, PLATFORMS
|
|
|
|
from .renault_hub import RenaultHub
|
2024-04-30 15:10:40 +00:00
|
|
|
from .services import setup_services
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
2024-04-30 15:39:03 +00:00
|
|
|
RenaultConfigEntry = ConfigEntry[RenaultHub]
|
2024-04-30 15:10:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
|
|
"""Set up the Renault component."""
|
|
|
|
setup_services(hass)
|
|
|
|
return True
|
2021-07-28 19:41:11 +00:00
|
|
|
|
|
|
|
|
2024-04-30 15:39:03 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, config_entry: RenaultConfigEntry
|
|
|
|
) -> bool:
|
2021-07-28 19:41:11 +00:00
|
|
|
"""Load a config entry."""
|
|
|
|
renault_hub = RenaultHub(hass, config_entry.data[CONF_LOCALE])
|
|
|
|
try:
|
|
|
|
login_success = await renault_hub.attempt_login(
|
|
|
|
config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD]
|
|
|
|
)
|
2023-02-09 15:55:02 +00:00
|
|
|
except (aiohttp.ClientConnectionError, GigyaException) as exc:
|
2024-03-17 23:40:38 +00:00
|
|
|
raise ConfigEntryNotReady from exc
|
2021-07-28 19:41:11 +00:00
|
|
|
|
|
|
|
if not login_success:
|
2024-03-17 23:40:38 +00:00
|
|
|
raise ConfigEntryAuthFailed
|
2021-07-28 19:41:11 +00:00
|
|
|
|
2023-07-31 10:17:51 +00:00
|
|
|
try:
|
|
|
|
await renault_hub.async_initialise(config_entry)
|
2023-11-20 11:58:55 +00:00
|
|
|
except aiohttp.ClientError as exc:
|
2024-03-17 23:40:38 +00:00
|
|
|
raise ConfigEntryNotReady from exc
|
2021-07-28 19:41:11 +00:00
|
|
|
|
2024-04-30 15:39:03 +00:00
|
|
|
config_entry.runtime_data = renault_hub
|
2021-07-28 19:41:11 +00:00
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
2021-07-28 19:41:11 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2024-04-30 15:39:03 +00:00
|
|
|
async def async_unload_entry(
|
|
|
|
hass: HomeAssistant, config_entry: RenaultConfigEntry
|
|
|
|
) -> bool:
|
2021-07-28 19:41:11 +00:00
|
|
|
"""Unload a config entry."""
|
2024-04-30 15:10:40 +00:00
|
|
|
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|