Endoreversible thermodynamics