Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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
except (aiohue.LinkButtonNotPressed, aiohue.Unauthorized):
raise AuthenticationRequired
except (asyncio.TimeoutError, aiohue.RequestError):
raise CannotConnect
except aiohue.AiohueException:
LOGGER.exception("Unknown Hue linking error occurred")
raise AuthenticationRequired
async def update_api(api):
import aiohue
try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True
async def async_update_items(self):
"""Update sensors from the bridge."""
api = self.bridge.api.sensors
try:
start = monotonic()
with async_timeout.timeout(4):
await self.bridge.async_request_call(api.update())
except Unauthorized:
await self.bridge.handle_unauthorized_error()
return
except (asyncio.TimeoutError, AiohueException) as err:
_LOGGER.debug("Failed to fetch sensor: %s", err)
if not self.bridge.available:
return
_LOGGER.error("Unable to reach bridge %s (%s)", self.bridge.host, err)
self.bridge.available = False
return
finally:
_LOGGER.debug(
"Finished sensor request in %.3f seconds", monotonic() - start
)
if not self.bridge.available:
if is_group:
api_type = "group"
api = bridge.api.groups
else:
api_type = "light"
api = bridge.api.lights
try:
start = monotonic()
with async_timeout.timeout(4):
await bridge.async_request_call(api.update())
except aiohue.Unauthorized:
await bridge.handle_unauthorized_error()
return
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch %s: %s", api_type, err)
if not bridge.available:
return
_LOGGER.error("Unable to reach bridge %s (%s)", bridge.host, err)
bridge.available = False
for item_id, item in current.items():
if item_id not in progress_waiting:
item.async_schedule_update_ha_state()
return
finally:
_LOGGER.debug(
async def update_api(api):
import aiohue
try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True
async def update_api(api):
import aiohue
try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True
async def update_api(api):
import aiohue
try:
with async_timeout.timeout(10):
await api.update()
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
_LOGGER.debug("Failed to fetch sensors: %s", err)
return False
return True