From 1b099f2a5e4d50977c751d57cbc30defa703a5b9 Mon Sep 17 00:00:00 2001 From: Locxion Date: Sat, 3 Feb 2024 00:51:28 +0100 Subject: [PATCH] Added ApiKey check --- GoveeCSharpConnector/Interfaces/GoveeService.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/GoveeCSharpConnector/Interfaces/GoveeService.cs b/GoveeCSharpConnector/Interfaces/GoveeService.cs index 2f949a4..719800e 100644 --- a/GoveeCSharpConnector/Interfaces/GoveeService.cs +++ b/GoveeCSharpConnector/Interfaces/GoveeService.cs @@ -17,6 +17,7 @@ public class GoveeService : IGoveeService } public async Task> GetDevices(bool onlyLan = true) { + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); var apiDevices = await _apiService.GetDevices(); var devices = apiDevices.Select(apiDevice => new GoveeDevice() { DeviceId = apiDevice.DeviceId, DeviceName = apiDevice.DeviceName, Model = apiDevice.Model, Address = "onlyAvailableOnUdpRequest" }).ToList(); if (!onlyLan) @@ -29,7 +30,7 @@ public class GoveeService : IGoveeService var combinedDevices = (from goveeDevice in devices let matchingDevice = udpDevices.FirstOrDefault(x => x.device == goveeDevice.DeviceId) where matchingDevice is not null select - new GoveeDevice() { DeviceId = goveeDevice.DeviceId, DeviceName = goveeDevice.DeviceName, Model = goveeDevice.Model, Address = matchingDevice.ip }).ToList(); + new GoveeDevice { DeviceId = goveeDevice.DeviceId, DeviceName = goveeDevice.DeviceName, Model = goveeDevice.Model, Address = matchingDevice.ip }).ToList(); return combinedDevices; } @@ -44,6 +45,7 @@ public class GoveeService : IGoveeService var udpState = await _udpService.GetState(goveeDevice.Address); return new GoveeState() { State = udpState.onOff, Brightness = udpState.brightness, Color = udpState.color, ColorTempInKelvin = udpState.colorTempInKelvin }; } + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); var apiState = await _apiService.GetDeviceState(goveeDevice.DeviceId, goveeDevice.Model); return new GoveeState{State = apiState.Properties.PowerState, Brightness = apiState.Properties.Brightness, Color = apiState.Properties.Color, ColorTempInKelvin = apiState.Properties.ColorTemp}; } @@ -56,7 +58,7 @@ public class GoveeService : IGoveeService await _udpService.ToggleDevice(goveeDevice.Address, on); return; } - + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); await _apiService.ToggleState(goveeDevice.DeviceId, goveeDevice.Model, on); } @@ -68,7 +70,7 @@ public class GoveeService : IGoveeService await _udpService.SetBrightness(goveeDevice.Address, value); return; } - + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); await _apiService.SetBrightness(goveeDevice.DeviceId, goveeDevice.Model, value); } @@ -80,7 +82,7 @@ public class GoveeService : IGoveeService await _udpService.SetColor(goveeDevice.Address, color); return; } - + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); await _apiService.SetColor(goveeDevice.DeviceId, goveeDevice.Model, color); } @@ -92,7 +94,7 @@ public class GoveeService : IGoveeService await _udpService.SetColorTemp(goveeDevice.Address, value); return; } - + if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); await _apiService.SetColorTemp(goveeDevice.DeviceId, goveeDevice.Model, value); } } \ No newline at end of file