Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Frontier Silicon integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from afsapi import AFSAPI, ConnectionError as FSConnectionError
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_PIN, Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.exceptions import ConfigEntryNotReady
13 
14 from .const import CONF_WEBFSAPI_URL, DOMAIN
15 
16 PLATFORMS = [Platform.MEDIA_PLAYER]
17 
18 _LOGGER = logging.getLogger(__name__)
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
22  """Set up Frontier Silicon from a config entry."""
23 
24  webfsapi_url = entry.data[CONF_WEBFSAPI_URL]
25  pin = entry.data[CONF_PIN]
26 
27  afsapi = AFSAPI(webfsapi_url, pin)
28 
29  try:
30  await afsapi.get_power()
31  except FSConnectionError as exception:
32  raise ConfigEntryNotReady from exception
33 
34  hass.data.setdefault(DOMAIN, {})[entry.entry_id] = afsapi
35 
36  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
37 
38  return True
39 
40 
41 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
42  """Unload a config entry."""
43  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
44  hass.data[DOMAIN].pop(entry.entry_id)
45 
46  return unload_ok
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:21
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:41