1 """Utils for Sensibo integration."""
3 from __future__
import annotations
7 from pysensibo
import SensiboClient
8 from pysensibo.exceptions
import AuthenticationError
13 from .const
import LOGGER, SENSIBO_ERRORS, TIMEOUT
17 """Validate the api and return username."""
18 client = SensiboClient(
25 async
with asyncio.timeout(TIMEOUT):
26 device_query = await client.async_get_devices()
27 user_query = await client.async_get_me()
28 except AuthenticationError
as err:
29 LOGGER.error(
"Could not authenticate on Sensibo servers %s", err)
30 raise AuthenticationError
from err
31 except SENSIBO_ERRORS
as err:
32 LOGGER.error(
"Failed to get information from Sensibo servers %s", err)
33 raise ConnectionError
from err
35 devices = device_query[
"result"]
36 user: str = user_query[
"result"].
get(
"username")
38 LOGGER.error(
"Could not retrieve any devices from Sensibo servers")
41 LOGGER.error(
"Could not retrieve username from Sensibo servers")
47 """No devices from Sensibo api."""
51 """No username from Sensibo api."""
web.Response get(self, web.Request request, str config_key)
str async_validate_api(HomeAssistant hass, str api_key)
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)