public async Task <IActionResult> Settings() { var config = await ConfigStore.GetConfigAsync(); try { if (TempData["check-settings"] is bool b && b) { // This doesn't check if the access token is valid... var inst = await DiscoveryClient.GetDiscoveryInfo(); // ... but this does. var entities = await EntityClient.GetEntities(); ViewBag.Instance = $"Home Assistant instance: <b>{inst.LocationName} (Version {inst.Version}) [{inst.BaseUrl}]</b>"; } } catch (Exception ex) { await ConfigStore.ManipulateConfig(c => c.Settings.AccessToken = c.Settings.BaseUri = null); config = await ConfigStore.GetConfigAsync(); TempData.Remove(AlertManager.GRP_SUCCESS); Logger.LogError(ex, "Invalid system settings entered, or unable to reach Home Assistant with the specified information."); TempData.AddError("The settings entered are not valid. HACC is unable to reach your Home Assistant instance. Try your entries again, consult the <a target=\"_blank\" href=\"https://github.com/qJake/HADotNet.CommandCenter/wiki/Initial-System-Setup\">setup guide</a> for help, or check the logs (console) for more information."); // Reloads the request showing the error (TempData doesn't commit until a reload). return(RedirectToAction("Settings")); } return(View(config.Settings)); }