How to use the aiohue.Unauthorized 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 / tests / components / hue / test_light.py View on Github external
async def test_update_unauthorized(hass, mock_bridge):
    """Test bridge marked as not authorized if unauthorized during update."""
    mock_bridge.api.lights.update = Mock(side_effect=aiohue.Unauthorized)
    mock_bridge.api.groups.update = Mock(side_effect=aiohue.Unauthorized)
    await setup_bridge(hass, mock_bridge)
    assert len(mock_bridge.mock_requests) == 0
    assert len(hass.states.async_all()) == 0
    assert len(mock_bridge.handle_unauthorized_error.mock_calls) == 1
github home-assistant / home-assistant / tests / components / hue / test_light.py View on Github external
async def test_update_unauthorized(hass, mock_bridge):
    """Test bridge marked as not authorized if unauthorized during update."""
    mock_bridge.api.lights.update = Mock(side_effect=aiohue.Unauthorized)
    mock_bridge.api.groups.update = Mock(side_effect=aiohue.Unauthorized)
    await setup_bridge(hass, mock_bridge)
    assert len(mock_bridge.mock_requests) == 0
    assert len(hass.states.async_all()) == 0
    assert len(mock_bridge.handle_unauthorized_error.mock_calls) == 1
github home-assistant / home-assistant / tests / components / hue / test_sensor_base.py View on Github external
async def test_update_unauthorized(hass, mock_bridge):
    """Test bridge marked as not authorized if unauthorized during update."""
    mock_bridge.api.sensors.update = Mock(side_effect=aiohue.Unauthorized)
    await setup_bridge(hass, mock_bridge)
    assert len(mock_bridge.mock_requests) == 0
    assert len(hass.states.async_all()) == 0
    assert len(mock_bridge.handle_unauthorized_error.mock_calls) == 1
github home-assistant / home-assistant / homeassistant / components / hue / light.py View on Github external
"""Update either groups or lights from the bridge."""
    if not bridge.authorized:
        return

    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
github home-assistant / home-assistant / homeassistant / components / hue / sensor_base.py View on Github external
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