How to use the pydeconz.utils.async_get_api_key function in pydeconz

To help you get started, we’ve selected a few pydeconz 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 Kane610 / deconz / tests / test_utils.py View on Github external
async def test_get_api_key_with_credentials() -> None:
    """Test a successful call of get_api_key with user crendentials."""
    session = Mock()

    with patch(
        "pydeconz.utils.async_request",
        new=CoroutineMock(return_value=[{"success": {"username": API_KEY}}]),
    ):
        response = await utils.async_get_api_key(
            session, IP, PORT, username="user", password="pass"
        )

    assert response == API_KEY
github Kane610 / deconz / pydeconz / __main__.py View on Github external
async def main(loop, **kwargs):
    """
    """
    if "api_key" not in kwargs:
        api_key = await async_get_api_key(loop, **kwargs)
        kwargs["api_key"] = api_key
        print(api_key)
    websession = aiohttp.ClientSession(loop=loop)
    deconz = DeconzSession(loop, websession, **kwargs)
    result = await deconz.async_load_parameters()
    if result is False:
        print("Failed to setup deCONZ")
        return False
    deconz.start()
    from pprint import pprint

    pprint(deconz.__dict__)
    # await deconz.async_delete_state('/lights/2/groups', {'reset':'true'})
github home-assistant / home-assistant / homeassistant / components / deconz / config_flow.py View on Github external
async def async_step_link(self, user_input=None):
        """Attempt to link with the deCONZ bridge."""
        errors = {}

        if user_input is not None:
            session = aiohttp_client.async_get_clientsession(self.hass)

            try:
                with async_timeout.timeout(10):
                    api_key = await async_get_api_key(session, **self.deconz_config)

            except (ResponseError, RequestError, asyncio.TimeoutError):
                errors["base"] = "no_key"

            else:
                self.deconz_config[CONF_API_KEY] = api_key
                return await self._create_entry()

        return self.async_show_form(step_id="link", errors=errors)