def __init__(self, hass, store, providers): """Initialize the auth manager.""" self._store = store self._providers = providers self.login_flow = data_entry_flow.FlowManager( hass, self._async_create_login_flow, self._async_finish_login_flow) self.access_tokens = {}
def manager(): """Return a flow manager.""" handlers = Registry() entries = [] async def async_create_flow(handler_name, *, context, data): handler = handlers.get(handler_name) if handler is None: raise data_entry_flow.UnknownHandler flow = handler() flow.init_step = context.get("init_step", "init") flow.source = context.get("source") return flow async def async_add_entry(flow, result): if result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY: result["source"] = flow.context.get("source") entries.append(result) return result manager = data_entry_flow.FlowManager(None, async_create_flow, async_add_entry) manager.mock_created_entries = entries manager.mock_reg_handler = handlers.register return manager
def manager(): """Return a flow manager.""" handlers = Registry() entries = [] async def async_create_flow(handler_name, *, context, data): handler = handlers.get(handler_name) if handler is None: raise data_entry_flow.UnknownHandler flow = handler() flow.init_step = context.get('init_step', 'init') \ if context is not None else 'init' flow.source = context.get('source') \ if context is not None else 'user_input' return flow async def async_add_entry(flow, result): if result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY: result['source'] = flow.context.get('source') \ if flow.context is not None else 'user' entries.append(result) return result manager = data_entry_flow.FlowManager(None, async_create_flow, async_add_entry) manager.mock_created_entries = entries manager.mock_reg_handler = handlers.register return manager
async def async_setup(hass): """Init mfa setup flow manager.""" async def _async_create_setup_flow(handler, context, data): """Create a setup flow. hanlder is a mfa module.""" mfa_module = hass.auth.get_auth_mfa_module(handler) if mfa_module is None: raise ValueError("Mfa module {} is not found".format(handler)) user_id = data.pop("user_id") return await mfa_module.async_setup_flow(user_id) async def _async_finish_setup_flow(flow, flow_result): _LOGGER.debug("flow_result: %s", flow_result) return flow_result hass.data[DATA_SETUP_FLOW_MGR] = data_entry_flow.FlowManager( hass, _async_create_setup_flow, _async_finish_setup_flow ) hass.components.websocket_api.async_register_command( WS_TYPE_SETUP_MFA, websocket_setup_mfa, SCHEMA_WS_SETUP_MFA ) hass.components.websocket_api.async_register_command( WS_TYPE_DEPOSE_MFA, websocket_depose_mfa, SCHEMA_WS_DEPOSE_MFA )
def __init__(self, hass: HomeAssistant, hass_config: dict) -> None: """Initialize the entry manager.""" self.hass = hass self.flow = data_entry_flow.FlowManager(hass, self._async_create_flow, self._async_finish_flow) self._hass_config = hass_config self._entries = [] # type: List[ConfigEntry] self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
def __init__(self, hass, hass_config): """Initialize the entry manager.""" self.hass = hass self.flow = data_entry_flow.FlowManager(hass, self._async_create_flow, self._async_finish_flow) self._hass_config = hass_config self._entries = None self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
def __init__(self, hass: HomeAssistant, store: auth_store.AuthStore, providers: _ProviderDict, mfa_modules: _MfaModuleDict) \ -> None: """Initialize the auth manager.""" self.hass = hass self._store = store self._providers = providers self._mfa_modules = mfa_modules self.login_flow = data_entry_flow.FlowManager( hass, self._async_create_login_flow, self._async_finish_login_flow)
def __init__(self, hass: HomeAssistant, hass_config: dict) -> None: """Initialize the entry manager.""" self.hass = hass self.flow = data_entry_flow.FlowManager(hass, self._async_create_flow, self._async_finish_flow) self.options = OptionsFlowManager(hass) self._hass_config = hass_config self._entries: List[ConfigEntry] = [] self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY) EntityRegistryDisabledHandler(hass).async_setup()
async def test_finish_callback_change_result_type(hass): """Test finish callback can change result type.""" class TestFlow(data_entry_flow.FlowHandler): VERSION = 1 async def async_step_init(self, input): """Return init form with one input field 'count'.""" if input is not None: return self.async_create_entry(title="init", data=input) return self.async_show_form( step_id="init", data_schema=vol.Schema({"count": int}) ) async def async_create_flow(handler_name, *, context, data): """Create a test flow.""" return TestFlow() async def async_finish_flow(flow, result): """Redirect to init form if count <= 1.""" if result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY: if result["data"] is None or result["data"].get("count", 0) <= 1: return flow.async_show_form( step_id="init", data_schema=vol.Schema({"count": int}) ) else: result["result"] = result["data"]["count"] return result manager = data_entry_flow.FlowManager(hass, async_create_flow, async_finish_flow) result = await manager.async_init("test") assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "init" result = await manager.async_configure(result["flow_id"], {"count": 0}) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "init" assert "result" not in result result = await manager.async_configure(result["flow_id"], {"count": 2}) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["result"] == 2
async def test_finish_callback_change_result_type(hass): """Test finish callback can change result type.""" class TestFlow(data_entry_flow.FlowHandler): VERSION = 1 async def async_step_init(self, input): """Return init form with one input field 'count'.""" if input is not None: return self.async_create_entry(title='init', data=input) return self.async_show_form(step_id='init', data_schema=vol.Schema({'count': int})) async def async_create_flow(handler_name, *, context, data): """Create a test flow.""" return TestFlow() async def async_finish_flow(flow, result): """Redirect to init form if count <= 1.""" if result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY: if (result['data'] is None or result['data'].get('count', 0) <= 1): return flow.async_show_form(step_id='init', data_schema=vol.Schema( {'count': int})) else: result['result'] = result['data']['count'] return result manager = data_entry_flow.FlowManager(hass, async_create_flow, async_finish_flow) result = await manager.async_init('test') assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'init' result = await manager.async_configure(result['flow_id'], {'count': 0}) assert result['type'] == data_entry_flow.RESULT_TYPE_FORM assert result['step_id'] == 'init' assert 'result' not in result result = await manager.async_configure(result['flow_id'], {'count': 2}) assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result['result'] == 2
def manager(): """Return a flow manager.""" handlers = Registry() entries = [] async def async_create_flow(handler_name): handler = handlers.get(handler_name) if handler is None: raise data_entry_flow.UnknownHandler return handler() async def async_add_entry(result): entries.append(result) manager = data_entry_flow.FlowManager( None, async_create_flow, async_add_entry) manager.mock_created_entries = entries manager.mock_reg_handler = handlers.register return manager
def manager(): """Return a flow manager.""" handlers = Registry() entries = [] async def async_create_flow(handler_name, *, source, data): handler = handlers.get(handler_name) if handler is None: raise data_entry_flow.UnknownHandler return handler() async def async_add_entry(result): if (result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY): entries.append(result) manager = data_entry_flow.FlowManager(None, async_create_flow, async_add_entry) manager.mock_created_entries = entries manager.mock_reg_handler = handlers.register return manager
def __init__(self, hass: HomeAssistant) -> None: """Initialize the options manager.""" self.hass = hass self.flow = data_entry_flow.FlowManager(hass, self._async_create_flow, self._async_finish_flow)