async def test_form_with_auth_abort(hass): """Test we handle abort after error.""" with patch( "homeassistant.components.nam.NettigoAirMonitor.initialize", side_effect=AuthFailed("Auth Error"), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=VALID_CONFIG, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "credentials" with patch( "homeassistant.components.nam.NettigoAirMonitor.initialize" ), patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address", side_effect=CannotGetMac("Cannot get MAC address from device"), ): result = await hass.config_entries.flow.async_configure( result["flow_id"], VALID_AUTH, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "device_unsupported"
async def test_form_abort(hass): """Test we handle abort after error.""" with patch( "homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value=DEVICE_CONFIG, ), patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address", side_effect=CannotGetMac("Cannot get MAC address from device"), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=VALID_CONFIG, ) assert result["type"] == data_entry_flow.FlowResultType.ABORT assert result["reason"] == "device_unsupported"
result = await hass.config_entries.flow.async_init( DOMAIN, data=DISCOVERY_INFO, context={"source": SOURCE_ZEROCONF}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @pytest.mark.parametrize( "error", [ (ApiError("API Error"), "cannot_connect"), (CannotGetMac("Cannot get MAC address from device"), "device_unsupported"), ], ) async def test_zeroconf_errors(hass, error): """Test we handle errors.""" exc, reason = error with patch( "homeassistant.components.nam.NettigoAirMonitor.initialize", side_effect=exc, ): result = await hass.config_entries.flow.async_init( DOMAIN, data=DISCOVERY_INFO, context={"source": SOURCE_ZEROCONF}, )
result = await hass.config_entries.flow.async_init( DOMAIN, data=DISCOVERY_INFO, context={"source": SOURCE_ZEROCONF}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @pytest.mark.parametrize( "error", [ (ApiError("Invalid response from device 10.10.2.3: 404"), "cannot_connect"), (CannotGetMac("Cannot get MAC address from device"), "device_unsupported"), ], ) async def test_zeroconf_errors(hass, error): """Test we handle errors.""" exc, reason = error with patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address", side_effect=exc, ): result = await hass.config_entries.flow.async_init( DOMAIN, data=DISCOVERY_INFO, context={"source": SOURCE_ZEROCONF}, )