Exemple #1
0
    async def async_step_link(self,
                              user_input: dict[str, Any] | None = None
                              ) -> FlowResult:
        """Attempt to link with the deCONZ bridge."""
        errors: dict[str, str] = {}

        LOGGER.debug("Preparing linking with deCONZ gateway %s %d", self.host,
                     self.port)

        if user_input is not None:
            session = aiohttp_client.async_get_clientsession(self.hass)
            deconz_session = DeconzSession(session, self.host, self.port)

            try:
                async with async_timeout.timeout(10):
                    api_key = await deconz_session.get_api_key()

            except LinkButtonNotPressed:
                errors["base"] = "linking_not_possible"

            except (ResponseError, RequestError, asyncio.TimeoutError):
                errors["base"] = "no_key"

            else:
                self.api_key = api_key
                return await self._create_entry()

        return self.async_show_form(step_id="link", errors=errors)
Exemple #2
0
    async def async_step_link(self,
                              user_input: dict[str, Any] | None = None
                              ) -> FlowResult:
        """Attempt to link with the deCONZ bridge."""
        errors: dict[str, str] = {}

        LOGGER.debug("Preparing linking with deCONZ gateway %s",
                     pformat(self.deconz_config))

        if user_input is not None:
            session = aiohttp_client.async_get_clientsession(self.hass)
            deconz_session = DeconzSession(
                session,
                host=self.deconz_config[CONF_HOST],
                port=self.deconz_config[CONF_PORT],
            )

            try:
                async with async_timeout.timeout(10):
                    api_key = await deconz_session.get_api_key()

            except (ResponseError, RequestError, asyncio.TimeoutError):
                errors["base"] = "no_key"

            else:
                self.deconz_config[CONF_API_KEY] = api_key
                return await self._create_entry()

        return self.async_show_form(step_id="link", errors=errors)