Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for Renault devices."""
2 
3 import aiohttp
4 from renault_api.gigya.exceptions import GigyaException
5 
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
8 from homeassistant.core import HomeAssistant
9 from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
10 from homeassistant.helpers import config_validation as cv, device_registry as dr
11 from homeassistant.helpers.typing import ConfigType
12 
13 from .const import CONF_LOCALE, DOMAIN, PLATFORMS
14 from .renault_hub import RenaultHub
15 from .services import setup_services
16 
17 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
18 type RenaultConfigEntry = ConfigEntry[RenaultHub]
19 
20 
21 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
22  """Set up the Renault component."""
23  setup_services(hass)
24  return True
25 
26 
28  hass: HomeAssistant, config_entry: RenaultConfigEntry
29 ) -> bool:
30  """Load a config entry."""
31  renault_hub = RenaultHub(hass, config_entry.data[CONF_LOCALE])
32  try:
33  login_success = await renault_hub.attempt_login(
34  config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD]
35  )
36  except (aiohttp.ClientConnectionError, GigyaException) as exc:
37  raise ConfigEntryNotReady from exc
38 
39  if not login_success:
40  raise ConfigEntryAuthFailed
41 
42  try:
43  await renault_hub.async_initialise(config_entry)
44  except aiohttp.ClientError as exc:
45  raise ConfigEntryNotReady from exc
46 
47  config_entry.runtime_data = renault_hub
48 
49  await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
50 
51  return True
52 
53 
55  hass: HomeAssistant, config_entry: RenaultConfigEntry
56 ) -> bool:
57  """Unload a config entry."""
58  return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
59 
60 
62  hass: HomeAssistant, config_entry: RenaultConfigEntry, device_entry: dr.DeviceEntry
63 ) -> bool:
64  """Remove a config entry from a device."""
65  return not device_entry.identifiers.intersection(
66  (DOMAIN, vin) for vin in config_entry.runtime_data.vehicles
67  )
bool async_unload_entry(HomeAssistant hass, RenaultConfigEntry config_entry)
Definition: __init__.py:56
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:21
bool async_remove_config_entry_device(HomeAssistant hass, RenaultConfigEntry config_entry, dr.DeviceEntry device_entry)
Definition: __init__.py:63
bool async_setup_entry(HomeAssistant hass, RenaultConfigEntry config_entry)
Definition: __init__.py:29