Home Assistant Unofficial Reference 2024.12.1
helpers.py
Go to the documentation of this file.
1 """Support for the Sabnzbd service."""
2 
3 from pysabnzbd import SabnzbdApi, SabnzbdApiException
4 
5 from homeassistant.const import CONF_API_KEY, CONF_URL
6 from homeassistant.core import _LOGGER, HomeAssistant
7 from homeassistant.helpers.aiohttp_client import async_get_clientsession
8 
9 
10 async def get_client(hass: HomeAssistant, data):
11  """Get Sabnzbd client."""
12  api_key = data[CONF_API_KEY]
13  url = data[CONF_URL]
14 
15  sab_api = SabnzbdApi(
16  url,
17  api_key,
18  session=async_get_clientsession(hass, False),
19  )
20  try:
21  await sab_api.check_available()
22  except SabnzbdApiException as exception:
23  _LOGGER.error("Connection to SABnzbd API failed: %s", exception.message)
24  return False
25 
26  return sab_api
def get_client(HomeAssistant hass, data)
Definition: helpers.py:10
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)