Added ApiKey check

This commit is contained in:
Locxion
2024-02-03 00:51:28 +01:00
parent b8c838caa3
commit 1b099f2a5e

View File

@ -17,6 +17,7 @@ public class GoveeService : IGoveeService
}
public async Task<List<GoveeDevice>> 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);
}
}