Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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