A washing machine comprises a drum and a heat pump system for heating water to be fed to the drum in a washing program. The heat pump system has an evaporator in heat exchange relationship with a room air flow and a condenser in heat exchange relationship with water to be heated, an air deflector being configured to divert said room air flow downstream the evaporator away from the condenser in a water heating configuration and to convey said air towards the condenser in a room air dehumidifying configuration of the washing machine.