public async Task <IActionResult> OnGetAsync() { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext); return(await DevicesApi.GetSmartMeDeviceConfigurationAsync(tokenData.AccessToken, Id, new ResultHandler <SmartMeDeviceConfiguration> { OnSuccess = (deviceConfig) => { DeviceConfig = deviceConfig; return Page(); }, OnError = DefaultErrorHandler.Handle })); }
public static async Task DeviceConfigurationAsync(UserPassword credentials) { // We will use this device to fetch its details later Device sampleDevice; // Get all devices { Helpers.WriteConsoleTitle("Get all devices"); List <Device> devices = await DevicesApi.GetDevicesAsync(credentials); foreach (var device in devices) { Console.WriteLine($"Id: {device.Id}, Name: {device.Name}"); } // Store the first device to show fow to fetch its details in various ways. Make sure you have at least // one device in your smart-me account. sampleDevice = devices.First(); } // Get smart-me Device Configuration { Helpers.WriteConsoleTitle("Get smart-me device configuration"); var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id); Console.WriteLine($"Id: {configuration.Id}, UploadInterval: {configuration.UploadInterval}"); } // Modify smart-me device configuration { Helpers.WriteConsoleTitle("Set smart-me device configuration"); var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id); configuration.DevicePinCode = "1234"; try { await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } Thread.Sleep(5000); configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, sampleDevice.Id); configuration.DevicePinCode = "7890"; try { await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } Thread.Sleep(5000); } }