Home Assistant Unofficial Reference 2024.12.1
subscription.py
Go to the documentation of this file.
1 """Subscription information."""
2 
3 from __future__ import annotations
4 
5 import asyncio
6 import logging
7 from typing import Any
8 
9 from aiohttp.client_exceptions import ClientError
10 from hass_nabucasa import Cloud, cloud_api
11 
12 from .client import CloudClient
13 from .const import REQUEST_TIMEOUT
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 
18 async def async_subscription_info(cloud: Cloud[CloudClient]) -> dict[str, Any] | None:
19  """Fetch the subscription info."""
20  try:
21  async with asyncio.timeout(REQUEST_TIMEOUT):
22  return await cloud_api.async_subscription_info(cloud)
23  except TimeoutError:
24  _LOGGER.error(
25  (
26  "A timeout of %s was reached while trying to fetch subscription"
27  " information"
28  ),
29  REQUEST_TIMEOUT,
30  )
31  except ClientError:
32  _LOGGER.error("Failed to fetch subscription information")
33 
34  return None
35 
36 
38  cloud: Cloud[CloudClient],
39 ) -> dict[str, Any] | None:
40  """Migrate a paypal agreement from legacy."""
41  try:
42  async with asyncio.timeout(REQUEST_TIMEOUT):
43  return await cloud_api.async_migrate_paypal_agreement(cloud)
44  except TimeoutError:
45  _LOGGER.error(
46  "A timeout of %s was reached while trying to start agreement migration",
47  REQUEST_TIMEOUT,
48  )
49  except ClientError as exception:
50  _LOGGER.error("Failed to start agreement migration - %s", exception)
51 
52  return None
dict[str, Any]|None async_migrate_paypal_agreement(Cloud[CloudClient] cloud)
Definition: subscription.py:39
dict[str, Any]|None async_subscription_info(Cloud[CloudClient] cloud)
Definition: subscription.py:18