Exemplo n.º 1
0
async def test_full_flow(hass):
    """Check classic use case."""
    hass.data[DOMAIN] = {}
    register_flow_implementation(hass, CLIENT_ID_VALUE, CLIENT_SECRET_VALUE)
    flow = config_flow.SomfyFlowHandler()
    flow.hass = hass
    hass.config.api = Mock(base_url='https://example.com')
    flow._get_authorization_url = Mock(return_value=mock_coro((AUTH_URL,
                                                               'state')))
    result = await flow.async_step_import()
    assert result['type'] == data_entry_flow.RESULT_TYPE_EXTERNAL_STEP
    assert result['url'] == AUTH_URL
    result = await flow.async_step_auth("my_super_code")
    assert result['type'] == data_entry_flow.RESULT_TYPE_EXTERNAL_STEP_DONE
    assert result['step_id'] == 'creation'
    assert flow.code == 'my_super_code'
    with patch.object(SomfyApi,
                      'request_token',
                      return_value={"access_token": "super_token"}):
        result = await flow.async_step_creation()
    assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result['data']['refresh_args'] == {
        'client_id': CLIENT_ID_VALUE,
        'client_secret': CLIENT_SECRET_VALUE
    }
    assert result['title'] == 'Somfy'
    assert result['data']['token'] == {"access_token": "super_token"}
Exemplo n.º 2
0
async def test_full_flow(hass):
    """Check classic use case."""
    hass.data[DOMAIN] = {}
    register_flow_implementation(hass, CLIENT_ID_VALUE, CLIENT_SECRET_VALUE)
    flow = config_flow.SomfyFlowHandler()
    flow.hass = hass
    hass.config.api = Mock(base_url="https://example.com")
    flow._get_authorization_url = Mock(return_value=mock_coro((AUTH_URL,
                                                               "state")))
    result = await flow.async_step_import()
    assert result["type"] == data_entry_flow.RESULT_TYPE_EXTERNAL_STEP
    assert result["url"] == AUTH_URL
    result = await flow.async_step_auth("my_super_code")
    assert result["type"] == data_entry_flow.RESULT_TYPE_EXTERNAL_STEP_DONE
    assert result["step_id"] == "creation"
    assert flow.code == "my_super_code"
    with patch.object(SomfyApi,
                      "request_token",
                      return_value={"access_token": "super_token"}):
        result = await flow.async_step_creation()
    assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
    assert result["data"]["refresh_args"] == {
        "client_id": CLIENT_ID_VALUE,
        "client_secret": CLIENT_SECRET_VALUE,
    }
    assert result["title"] == "Somfy"
    assert result["data"]["token"] == {"access_token": "super_token"}
Exemplo n.º 3
0
async def async_setup(hass, config):
    """Set up the Somfy component."""
    if DOMAIN not in config:
        return True

    hass.data[DOMAIN] = {}

    config_flow.register_flow_implementation(
        hass, config[DOMAIN][CONF_CLIENT_ID],
        config[DOMAIN][CONF_CLIENT_SECRET])

    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}))

    return True