1 """deCONZ API representation."""
3 from __future__
import annotations
7 from pydeconz
import DeconzSession, errors
13 from ..const
import LOGGER
14 from ..errors
import AuthenticationRequired, CannotConnect
15 from .config
import DeconzConfig
19 hass: HomeAssistant, config_entry: ConfigEntry
21 """Create a gateway object and verify configuration."""
22 session = aiohttp_client.async_get_clientsession(hass)
24 config = DeconzConfig.from_config_entry(config_entry)
25 api = DeconzSession(session, config.host, config.port, config.api_key)
27 async
with asyncio.timeout(10):
28 await api.refresh_state()
30 except errors.Unauthorized
as err:
31 LOGGER.warning(
"Invalid key for deCONZ at %s", config.host)
32 raise AuthenticationRequired
from err
34 except (TimeoutError, errors.RequestError, errors.ResponseError)
as err:
35 LOGGER.error(
"Error connecting to deCONZ gateway at %s", config.host)
36 raise CannotConnect
from err
DeconzSession get_deconz_api(HomeAssistant hass, ConfigEntry config_entry)