Rewrite thermostat and fix api tests
Merge