diff --git a/GoveeCSharpConnector/Interfaces/IGoveeHttpService.cs b/GoveeCSharpConnector/Interfaces/IGoveeHttpService.cs index 8f2f108..1377053 100644 --- a/GoveeCSharpConnector/Interfaces/IGoveeHttpService.cs +++ b/GoveeCSharpConnector/Interfaces/IGoveeHttpService.cs @@ -64,5 +64,20 @@ public interface IGoveeHttpService /// Value 1-100 /// Task> SetBrightness(string deviceId, string deviceModel, int value); - + /// + /// Sets the LightScene of a single Govee Device + /// + /// Device Id Guid as string + /// Device Model Number as string + /// Number of the Scene + /// + Task> SetLightScene(string deviceId, string deviceModel, int sceneValue); + /// + /// Sets the DiyScene of a single Govee Device + /// + /// Device Id Guid as string + /// Device Model Number as string + /// Number of the Scene + /// + Task> SetDiyScene(string deviceId, string deviceModel, int sceneValue); } \ No newline at end of file diff --git a/GoveeCSharpConnector/Services/GoveeHttpService.cs b/GoveeCSharpConnector/Services/GoveeHttpService.cs index 56a9440..cf7662a 100644 --- a/GoveeCSharpConnector/Services/GoveeHttpService.cs +++ b/GoveeCSharpConnector/Services/GoveeHttpService.cs @@ -14,6 +14,7 @@ public class GoveeHttpService : IGoveeHttpService private const string GoveeDevicesEndpoint = "/router/api/v1/user/devices"; private const string GoveeControlEndpoint = "/router/api/v1/device/control"; 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 JsonSerializerOptions? _jsonOptions = new() { @@ -126,7 +127,7 @@ public class GoveeHttpService : IGoveeHttpService }}"; 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) { serviceResponse.Success = false; @@ -160,7 +161,7 @@ public class GoveeHttpService : IGoveeHttpService }}"; 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) { serviceResponse.Success = false; @@ -198,7 +199,7 @@ public class GoveeHttpService : IGoveeHttpService }}"; 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) { serviceResponse.Success = false; @@ -210,5 +211,68 @@ public class GoveeHttpService : IGoveeHttpService serviceResponse.Message = ""; return serviceResponse; } + /// + public async Task> SetLightScene(string deviceId, string deviceModel, int sceneValue) + { + var serviceResponse = new ServiceResponse(); + + 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; + } + /// + public async Task> SetDiyScene(string deviceId, string deviceModel, int sceneValue) + { + var serviceResponse = new ServiceResponse(); + + 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; + } } \ No newline at end of file