async def test_import_flow_no_update(hass, pyscript_bypass_setup): """Test import config flow doesn't update existing entry when data is same.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured"
async def test_options_flow_user_no_change(hass, pyscript_bypass_setup): """Test options flow aborts when options don't change.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=PYSCRIPT_SCHEMA({ CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True }), ) await hass.async_block_till_done() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY entry = result["result"] result = await hass.config_entries.options.async_init(entry.entry_id) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "init" result = await hass.config_entries.options.async_configure( result["flow_id"], user_input={ CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True }) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "no_update" result = await hass.config_entries.options.async_configure( result["flow_id"], user_input=None) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == ""
async def test_options_flow_import(hass, pyscript_bypass_setup): """Test options flow aborts because configuration needs to be managed via configuration.yaml.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({ CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True }), ) await hass.async_block_till_done() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY entry = result["result"] result = await hass.config_entries.options.async_init(entry.entry_id, data=None) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "no_ui_configuration_allowed" result = await hass.config_entries.options.async_configure( result["flow_id"], user_input=None) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == ""
async def test_import_flow_update_import(hass, pyscript_bypass_setup): """Test import config flow update includes `allow_all_imports` in update when updated entry was imported entry.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({ CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True }), ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data={"apps": { "test_app": { "param": 1 } }}) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "updated_entry" assert hass.config_entries.async_entries(DOMAIN)[0].data == { "apps": { "test_app": { "param": 1 } } }
async def test_import_flow_update_user(hass): """Test import config flow update excludes `allow_all_imports` from being updated when updated entry was a user entry.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=PYSCRIPT_SCHEMA({CONF_ALLOW_ALL_IMPORTS: True})) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data={"apps": { "test_app": { "param": 1 } }}) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "updated_entry" assert hass.config_entries.async_entries(DOMAIN)[0].data == { CONF_ALLOW_ALL_IMPORTS: True, "apps": { "test_app": { "param": 1 } }, }
async def test_import_flow_update_allow_all_imports(hass): """Test import config flow updates existing entry when `allow_all_imports` has changed.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_ALLOW_ALL_IMPORTS: True}) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "updated_entry"
async def test_import_flow_update_apps_to_none(hass, pyscript_bypass_setup): """Test import config flow updates existing entry when `apps` has changed from something to None.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({"apps": { "test_app": { "param": 1 } }})) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data={}) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "updated_entry"
async def test_config_entry_reload(hass): """Test that config entry reload does not duplicate listeners.""" with patch("homeassistant.config.load_yaml_config_file", return_value={}): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=PYSCRIPT_SCHEMA({ CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True }), ) await hass.async_block_till_done() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY entry = result["result"] listeners = hass.bus.async_listeners() await hass.config_entries.async_reload(entry.entry_id) await hass.async_block_till_done() assert listeners == hass.bus.async_listeners()
async def test_options_flow_user_change(hass): """Test options flow updates config entry when options change.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=PYSCRIPT_SCHEMA({CONF_ALLOW_ALL_IMPORTS: True})) await hass.async_block_till_done() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY entry = result["result"] result = await hass.config_entries.options.async_init(entry.entry_id) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "init" result = await hass.config_entries.options.async_configure( result["flow_id"], user_input={CONF_ALLOW_ALL_IMPORTS: False}) await hass.async_block_till_done() assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "" assert entry.data[CONF_ALLOW_ALL_IMPORTS] is False
async def test_import_flow(hass, pyscript_bypass_setup): """Test import config flow works.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY