Rigorous thermodynamic treatment of gas adsorption