Fixed color check
Added Json Options for Api Request
This commit is contained in:
@ -11,7 +11,10 @@ public class GoveeApiService : IGoveeApiService
|
|||||||
private string _apiKey = string.Empty;
|
private string _apiKey = string.Empty;
|
||||||
private const string GoveeApiAddress = "https://developer-api.govee.com/v1";
|
private const string GoveeApiAddress = "https://developer-api.govee.com/v1";
|
||||||
private readonly HttpClient _httpClient = new();
|
private readonly HttpClient _httpClient = new();
|
||||||
|
private readonly JsonSerializerOptions? _jsonOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||||
|
};
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void SetApiKey(string apiKey)
|
public void SetApiKey(string apiKey)
|
||||||
{
|
{
|
||||||
@ -74,7 +77,7 @@ public class GoveeApiService : IGoveeApiService
|
|||||||
Value = commandObject
|
Value = commandObject
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var httpContent = new StringContent(JsonSerializer.Serialize(commandRequest), Encoding.UTF8, "application/json");
|
var httpContent = new StringContent(JsonSerializer.Serialize(commandRequest, _jsonOptions), Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.PutAsync($"{GoveeApiAddress}/devices/control", httpContent);
|
var response = await _httpClient.PutAsync($"{GoveeApiAddress}/devices/control", httpContent);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
throw new Exception($"Govee Api Request failed. Status code: {response.StatusCode}, Message: {response.Content}");
|
throw new Exception($"Govee Api Request failed. Status code: {response.StatusCode}, Message: {response.Content}");
|
||||||
|
@ -123,7 +123,7 @@ public class Program
|
|||||||
}
|
}
|
||||||
Console.WriteLine($"Please choose a Color to set {nameInput3} to ... (blue, red, green)");
|
Console.WriteLine($"Please choose a Color to set {nameInput3} to ... (blue, red, green)");
|
||||||
var colorInput = Console.ReadLine()?.ToLower();
|
var colorInput = Console.ReadLine()?.ToLower();
|
||||||
if (string.IsNullOrWhiteSpace(colorInput) || colorInput != "blue" || colorInput != "green" || colorInput != "red")
|
if (string.IsNullOrWhiteSpace(colorInput) || (colorInput != "blue" && colorInput != "green" && colorInput != "red"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Invalid Input!");
|
Console.WriteLine("Invalid Input!");
|
||||||
EndSegment();
|
EndSegment();
|
||||||
|
Reference in New Issue
Block a user