Energy conservation for inhomogeneous Euler equations