From a069133a68d64131370a6f25cf56c33971f99c32 Mon Sep 17 00:00:00 2001 From: Markus Bender Date: Sat, 3 Feb 2024 01:25:44 +0100 Subject: [PATCH] Set Api Key (#4) * Delete .gitignore * Added Readme, Added Nuget Infos in Project * Added GoveeService that unites Api and Udp Service Added ColorTemp Method to Udp Service * Added UdpListener check * Added ApiKey check * Moved Class and changed Namespace * Update GoveeCSharpConnector.csproj * Set Api Key on Request --- GoveeCSharpConnector/GoveeCSharpConnector.csproj | 2 +- GoveeCSharpConnector/Services/GoveeService.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/GoveeCSharpConnector/GoveeCSharpConnector.csproj b/GoveeCSharpConnector/GoveeCSharpConnector.csproj index 132f430..d11ed1f 100644 --- a/GoveeCSharpConnector/GoveeCSharpConnector.csproj +++ b/GoveeCSharpConnector/GoveeCSharpConnector.csproj @@ -12,7 +12,7 @@ https://github.com/Locxion/GoveeCSharpConnector https://github.com/Locxion/GoveeCSharpConnector https://github.com/Locxion/GoveeCSharpConnector/blob/main/LICENSE - 1.1.0 + 1.1.1 diff --git a/GoveeCSharpConnector/Services/GoveeService.cs b/GoveeCSharpConnector/Services/GoveeService.cs index 7a0c046..7c40ed3 100644 --- a/GoveeCSharpConnector/Services/GoveeService.cs +++ b/GoveeCSharpConnector/Services/GoveeService.cs @@ -18,6 +18,8 @@ public class GoveeService : IGoveeService public async Task> GetDevices(bool onlyLan = true) { if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); + _apiService.SetApiKey(GoveeApiKey); + 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) @@ -46,6 +48,7 @@ public class GoveeService : IGoveeService 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!"); + _apiService.SetApiKey(GoveeApiKey); 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}; } @@ -59,6 +62,7 @@ public class GoveeService : IGoveeService return; } if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); + _apiService.SetApiKey(GoveeApiKey); await _apiService.ToggleState(goveeDevice.DeviceId, goveeDevice.Model, on); } @@ -71,6 +75,7 @@ public class GoveeService : IGoveeService return; } if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); + _apiService.SetApiKey(GoveeApiKey); await _apiService.SetBrightness(goveeDevice.DeviceId, goveeDevice.Model, value); } @@ -83,6 +88,8 @@ public class GoveeService : IGoveeService return; } if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); + + _apiService.SetApiKey(GoveeApiKey); await _apiService.SetColor(goveeDevice.DeviceId, goveeDevice.Model, color); } @@ -95,6 +102,7 @@ public class GoveeService : IGoveeService return; } if (string.IsNullOrWhiteSpace(GoveeApiKey)) throw new Exception("No Govee Api Key Set!"); + _apiService.SetApiKey(GoveeApiKey); await _apiService.SetColorTemp(goveeDevice.DeviceId, goveeDevice.Model, value); } } \ No newline at end of file