#ifdef FIRMWARE_VARIANT_THERMOSTAT


void thermostat_loadSavedValues()
{
  thermostat_loadSetTemp();
  thermostat_loadSetTempLow();
  thermostat_loadSetTempLow2();
  thermostat_loadHeatingMode();
  thermostat_loadPreset();
}



void thermostat_saveValues()
{
  sendLog(F("TSTAT: saving values..."));
  thermostat_saveSetTemp();
  yield();
  thermostat_saveSetTempLow();
  yield();
  thermostat_saveSetTempLow2();
  yield();
  thermostat_saveHeatingMode();
  yield();
  sendLog(F("TSTAT: saved values to FS - DONE"));
}


bool thermostat_saveSetTemp()
{
  File configFile = LittleFS.open("/setTemp", "w");
  if (!configFile)
  {
    sendLog(F("Failed to write file /setTemp"), LOGLEVEL_ERROR);
    return false;
  }
  configFile.println(thermostat_setTemp);
  configFile.close();
  thermostat_setTempSaved = thermostat_setTemp;
  return true;
} // thermostat_saveSetTemp



bool thermostat_saveSetTempLow()
{
  File configFile = LittleFS.open("/setTempLow", "w");
  if (!configFile)
  {
    sendLog(F("Failed to write file /setTempLow"), LOGLEVEL_ERROR);
    return false;
  }
  configFile.println(thermostat_setTempLow);
  configFile.close();
  thermostat_setTempLowSaved = thermostat_setTempLow;
  return true;
} // saveSetTempLow



bool thermostat_saveSetTempLow2()
{
  File configFile = LittleFS.open("/setTempLow2", "w");
  if (!configFile)
  {
    sendLog(F("Failed to write file setTempLow2"), LOGLEVEL_ERROR);
    return false;
  }
  configFile.println(thermostat_setTempLow2);
  configFile.close();
  thermostat_setTempLow2Saved = thermostat_setTempLow2;
  return true;
} // thermostat_saveSetTempLow



bool thermostat_saveHeatingMode()
{
  File configFile = LittleFS.open("/heatingMode", "w");
  if (!configFile)
  {
    sendLog(F("Failed to write file /heatingMode"), LOGLEVEL_ERROR);
    return false;
  }
  configFile.println(thermostat_heatingMode);
  configFile.close();
  thermostat_heatingModeSaved = thermostat_heatingMode;
  return true;
} // thermostat_saveHeatingMode



bool thermostat_savePreset()
{ 
  File configFile = LittleFS.open("/preset", "w");
  if (!configFile)
  {
    sendLog(F("Failed to write file /preset"), LOGLEVEL_ERROR);
    return false;
  }
  configFile.println(thermostat_preset);
  configFile.close();
  thermostat_presetSaved = thermostat_preset;
  return true;
} // thermostat_savePreset





bool thermostat_loadSetTemp()
{
  File configFile = LittleFS.open("/setTemp", "r");
  if (!configFile)
  {
    Serial.println(F("NOTE: Failed to open file /setTemp"));
    return false;
  }
  String s = configFile.readStringUntil('\n');
  configFile.close();
  float _tmpSetTemp = s.toFloat();
  if (_tmpSetTemp >= confTherm.setTempMin && _tmpSetTemp <= confTherm.setTempMax)
  {
    thermostat_setTemp = _tmpSetTemp;
    thermostat_setTempSaved = _tmpSetTemp;
    return true;
  }
  else
    return false;
} // thermostat_loadSetTemp



bool thermostat_loadSetTempLow()
{ 
  File configFile = LittleFS.open("/setTempLow", "r");
  if (!configFile)
  {
    Serial.println(F("NOTE: Failed to open file /setTempLow"));
    return false;
  }
  String s = configFile.readStringUntil('\n');
  configFile.close();
  float _tmpSetTempLow = s.toFloat();
  if (_tmpSetTempLow >= thermostat_setTempLowMin && _tmpSetTempLow <= thermostat_setTempLowMax)
  {
    thermostat_setTempLow = _tmpSetTempLow;
    thermostat_setTempLowSaved = _tmpSetTempLow;
    return true;
  }
  else
    return false;
} // thermostat_loadSetTempLow



bool thermostat_loadSetTempLow2()
{ 
  File configFile = LittleFS.open("/setTempLow2", "r");
  if (!configFile)
  {
    Serial.println(F("NOTE: Failed to open file /setTempLow2"));
    return false;
  }
  String s = configFile.readStringUntil('\n');
  configFile.close();
  float _tmpSetTempLow2 = s.toFloat();
  if (_tmpSetTempLow2 >= thermostat_setTempLowMin && _tmpSetTempLow2 <= thermostat_setTempLowMax)
  {
    thermostat_setTempLow2 = _tmpSetTempLow2;
    thermostat_setTempLow2Saved = _tmpSetTempLow2;
    return true;
  }
  else
    return false;
} // thermostat_loadSetTempLow2



bool thermostat_loadHeatingMode()
{
  File configFile = LittleFS.open("/heatingMode", "r");
  if (!configFile)
  {
    Serial.println(F("NOTE: Failed to open file /heatingMode"));
    return false;
  }
  String s = configFile.readStringUntil('\n');
  configFile.close();
  int _tmpHeatingMode = s.toInt();
  if (_tmpHeatingMode >= 0 && _tmpHeatingMode <= 1)
  {
    thermostat_heatingMode = _tmpHeatingMode;
    thermostat_heatingModeSaved = _tmpHeatingMode;
    return true;
  }
  else
    return false;
} // thermostat_loadHeatingMode



bool thermostat_loadPreset()
{
  File configFile = LittleFS.open("/preset", "r");
  if (!configFile)
  {
    Serial.println(F("NOTE: Failed to open file /preset"));
    return false;
  }
  String s = configFile.readStringUntil('\n');
  configFile.close();
  int _tmpPreset = s.toInt();
  if (_tmpPreset >= 0 && _tmpPreset <= 2)
  {
    thermostat_preset = _tmpPreset;
    thermostat_presetSaved = _tmpPreset;
    return true;
  }
  else
    return false;
} // thermostat_loadPreset


#endif
