How to use the aiohue.Bridge 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 / bridge.py View on Github external
async def get_bridge(hass, host, username=None):
    """Create a bridge object and verify authentication."""
    bridge = aiohue.Bridge(
        host, username=username, websession=aiohttp_client.async_get_clientsession(hass)
    )

    try:
        with async_timeout.timeout(10):
            # Create username if we don't have one
            if not username:
                device_name = unicode_slug.slugify(
                    hass.config.location_name, max_length=19
                )
                await bridge.create_user(f"home-assistant#{device_name}")

            # Initialize bridge (and validate our username)
            await bridge.initialize()

        return bridge