Thermodynamics of a gas in equilibrium with two nonstoichiometric condensed phases. Application to metal/hydrogen systems