Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The AfterShip integration."""
2 
3 from __future__ import annotations
4 
5 from pyaftership import AfterShip, AfterShipException
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_API_KEY, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.exceptions import ConfigEntryNotReady
11 from homeassistant.helpers.aiohttp_client import async_get_clientsession
12 
13 PLATFORMS: list[Platform] = [Platform.SENSOR]
14 
15 type AfterShipConfigEntry = ConfigEntry[AfterShip]
16 
17 
18 async def async_setup_entry(hass: HomeAssistant, entry: AfterShipConfigEntry) -> bool:
19  """Set up AfterShip from a config entry."""
20 
21  session = async_get_clientsession(hass)
22  aftership = AfterShip(api_key=entry.data[CONF_API_KEY], session=session)
23 
24  try:
25  await aftership.trackings.list()
26  except AfterShipException as err:
27  raise ConfigEntryNotReady from err
28 
29  entry.runtime_data = aftership
30 
31  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
32 
33  return True
34 
35 
36 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
37  """Unload a config entry."""
38  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:36
bool async_setup_entry(HomeAssistant hass, AfterShipConfigEntry entry)
Definition: __init__.py:18
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)