how does a thermostat