How to use the aiohue.discovery.discover_nupnp function in aiohue

To help you get started, we’ve selected a few aiohue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / hue / config_flow.py View on Github external
async def async_step_init(self, user_input=None):
        """Handle a flow start."""
        if user_input is not None:
            self.host = self.context["host"] = user_input["host"]
            return await self.async_step_link()

        websession = aiohttp_client.async_get_clientsession(self.hass)

        try:
            with async_timeout.timeout(5):
                bridges = await discover_nupnp(websession=websession)
        except asyncio.TimeoutError:
            return self.async_abort(reason="discover_timeout")

        if not bridges:
            return self.async_abort(reason="no_bridges")

        # Find already configured hosts
        configured = configured_hosts(self.hass)

        hosts = [bridge.host for bridge in bridges if bridge.host not in configured]

        if not hosts:
            return self.async_abort(reason="all_configured")

        if len(hosts) == 1:
            self.host = hosts[0]