Added Set Scenes Methods
Changed Control Endpoints
This commit is contained in:
@ -64,5 +64,20 @@ public interface IGoveeHttpService
|
|||||||
/// <param name="value">Value 1-100</param>
|
/// <param name="value">Value 1-100</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<ServiceResponse<bool>> SetBrightness(string deviceId, string deviceModel, int value);
|
Task<ServiceResponse<bool>> SetBrightness(string deviceId, string deviceModel, int value);
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the LightScene of a single Govee Device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceId">Device Id Guid as string</param>
|
||||||
|
/// <param name="deviceModel">Device Model Number as string</param>
|
||||||
|
/// <param name="sceneValue">Number of the Scene</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ServiceResponse<bool>> SetLightScene(string deviceId, string deviceModel, int sceneValue);
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the DiyScene of a single Govee Device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceId">Device Id Guid as string</param>
|
||||||
|
/// <param name="deviceModel">Device Model Number as string</param>
|
||||||
|
/// <param name="sceneValue">Number of the Scene</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ServiceResponse<bool>> SetDiyScene(string deviceId, string deviceModel, int sceneValue);
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ public class GoveeHttpService : IGoveeHttpService
|
|||||||
private const string GoveeDevicesEndpoint = "/router/api/v1/user/devices";
|
private const string GoveeDevicesEndpoint = "/router/api/v1/user/devices";
|
||||||
private const string GoveeControlEndpoint = "/router/api/v1/device/control";
|
private const string GoveeControlEndpoint = "/router/api/v1/device/control";
|
||||||
private const string GoveeStateEndpoint = "/router/api/v1/device/state";
|
private const string GoveeStateEndpoint = "/router/api/v1/device/state";
|
||||||
|
private const string GoveeScenesEndpoint = "/router/api/v1/device/scenes";
|
||||||
private readonly HttpClient _httpClient = new();
|
private readonly HttpClient _httpClient = new();
|
||||||
private readonly JsonSerializerOptions? _jsonOptions = new()
|
private readonly JsonSerializerOptions? _jsonOptions = new()
|
||||||
{
|
{
|
||||||
@ -126,7 +127,7 @@ public class GoveeHttpService : IGoveeHttpService
|
|||||||
}}";
|
}}";
|
||||||
|
|
||||||
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeStateEndpoint}", content);
|
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
serviceResponse.Success = false;
|
serviceResponse.Success = false;
|
||||||
@ -160,7 +161,7 @@ public class GoveeHttpService : IGoveeHttpService
|
|||||||
}}";
|
}}";
|
||||||
|
|
||||||
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeStateEndpoint}", content);
|
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
serviceResponse.Success = false;
|
serviceResponse.Success = false;
|
||||||
@ -198,7 +199,7 @@ public class GoveeHttpService : IGoveeHttpService
|
|||||||
}}";
|
}}";
|
||||||
|
|
||||||
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeStateEndpoint}", content);
|
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
serviceResponse.Success = false;
|
serviceResponse.Success = false;
|
||||||
@ -210,5 +211,68 @@ public class GoveeHttpService : IGoveeHttpService
|
|||||||
serviceResponse.Message = "";
|
serviceResponse.Message = "";
|
||||||
return serviceResponse;
|
return serviceResponse;
|
||||||
}
|
}
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<ServiceResponse<bool>> SetLightScene(string deviceId, string deviceModel, int sceneValue)
|
||||||
|
{
|
||||||
|
var serviceResponse = new ServiceResponse<bool>();
|
||||||
|
|
||||||
|
var jsonPayload = $@"
|
||||||
|
{{
|
||||||
|
""requestId"": ""{Guid.NewGuid()}"",
|
||||||
|
""payload"": {{
|
||||||
|
""sku"": ""{deviceModel}"",
|
||||||
|
""device"": ""{deviceId}"",
|
||||||
|
""capability"": {{
|
||||||
|
""type"": ""devices.capabilities.dynamic_scene"",
|
||||||
|
""instance"": ""lightScene"",
|
||||||
|
""value"": {sceneValue}
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
}}";
|
||||||
|
|
||||||
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
|
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
serviceResponse.Success = false;
|
||||||
|
serviceResponse.Message = response.ReasonPhrase;
|
||||||
|
return serviceResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceResponse.Success = true;
|
||||||
|
serviceResponse.Message = "";
|
||||||
|
return serviceResponse;
|
||||||
|
}
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<ServiceResponse<bool>> SetDiyScene(string deviceId, string deviceModel, int sceneValue)
|
||||||
|
{
|
||||||
|
var serviceResponse = new ServiceResponse<bool>();
|
||||||
|
|
||||||
|
var jsonPayload = $@"
|
||||||
|
{{
|
||||||
|
""requestId"": ""{Guid.NewGuid()}"",
|
||||||
|
""payload"": {{
|
||||||
|
""sku"": ""{deviceModel}"",
|
||||||
|
""device"": ""{deviceId}"",
|
||||||
|
""capability"": {{
|
||||||
|
""type"": ""devices.capabilities.dynamic_scene"",
|
||||||
|
""instance"": ""diyScene"",
|
||||||
|
""value"": {sceneValue}
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
}}";
|
||||||
|
|
||||||
|
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
|
||||||
|
var response = await _httpClient.PostAsync($"{GoveeApiAddress}{GoveeControlEndpoint}", content);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
serviceResponse.Success = false;
|
||||||
|
serviceResponse.Message = response.ReasonPhrase;
|
||||||
|
return serviceResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceResponse.Success = true;
|
||||||
|
serviceResponse.Message = "";
|
||||||
|
return serviceResponse;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user