Compare commits
6 Commits
1b099f2a5e
...
main
Author | SHA1 | Date | |
---|---|---|---|
76ccf20c30 | |||
a069133a68 | |||
bb01b3342d | |||
602926c43e | |||
2eef997c6e | |||
bb9364c491 |
27
.github/workflows/nuget.yml
vendored
Normal file
27
.github/workflows/nuget.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
name: Release to NuGet
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master # Default release branch
|
||||
pull_request:
|
||||
branches:
|
||||
- master # Run the workflow for all pull requests on Branch Master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v1.5
|
||||
- name: Build
|
||||
run: dotnet build -c Release
|
||||
- name: Test
|
||||
run: dotnet test -c Release --no-build
|
||||
- name: Pack nugets
|
||||
run: dotnet pack -c Release --no-build --output .
|
||||
- name: Push to NuGet
|
||||
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_KEY}} --source https://api.nuget.org/v3/index.json
|
@ -12,16 +12,14 @@
|
||||
<PackageProjectUrl>https://github.com/Locxion/GoveeCSharpConnector</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/Locxion/GoveeCSharpConnector</RepositoryUrl>
|
||||
<PackageLicenseUrl>https://github.com/Locxion/GoveeCSharpConnector/blob/main/LICENSE</PackageLicenseUrl>
|
||||
<Version>1.1.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
|
||||
<PackageReference Include="System.Reactive" Version="6.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -12,7 +12,7 @@ public interface IGoveeUdpService
|
||||
/// <summary>
|
||||
/// Sends a Scan Command via Udp Multicast.
|
||||
/// </summary>
|
||||
/// <param name="timeout">Standard 200ms</param>
|
||||
/// <param name="timeout">Standard 250ms</param>
|
||||
/// <returns>List of GoveeUdpDevices</returns>
|
||||
Task<List<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null);
|
||||
|
||||
@ -21,7 +21,7 @@ public interface IGoveeUdpService
|
||||
/// </summary>
|
||||
/// <param name="deviceAddress">Ip Address of the Device</param>
|
||||
/// <param name="uniCastPort">Port of the Device. Standard 4003</param>
|
||||
/// <param name="timeout">Standard 200ms</param>
|
||||
/// <param name="timeout">Standard 250ms</param>
|
||||
/// <returns></returns>
|
||||
Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System.Xml.Linq;
|
||||
using GoveeCSharpConnector.Interfaces;
|
||||
using GoveeCSharpConnector.Objects;
|
||||
|
||||
namespace GoveeCSharpConnector.Interfaces;
|
||||
namespace GoveeCSharpConnector.Services;
|
||||
|
||||
public class GoveeService : IGoveeService
|
||||
{
|
||||
@ -18,6 +18,8 @@ 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!");
|
||||
_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);
|
||||
}
|
||||
}
|
@ -32,6 +32,8 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
/// <inheritdoc/>
|
||||
public async Task<List<GoveeUdpDevice>> GetDevices(TimeSpan? timeout = null)
|
||||
{
|
||||
if (!_udpListenerActive)
|
||||
throw new Exception("Udp Listener not started!");
|
||||
// Block this Method until current call reaches end of Method
|
||||
await _semaphore.WaitAsync();
|
||||
|
||||
@ -48,7 +50,7 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
};
|
||||
// Subscribe to ScanResultSubject
|
||||
var devicesTask = _scanResultSubject
|
||||
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(300)))
|
||||
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(250)))
|
||||
.ToList()
|
||||
.ToTask();
|
||||
|
||||
@ -73,6 +75,8 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
/// <inheritdoc/>
|
||||
public async Task<GoveeUdpState> GetState(string deviceAddress, int uniCastPort = 4003, TimeSpan? timeout = null)
|
||||
{
|
||||
if (!_udpListenerActive)
|
||||
throw new Exception("Udp Listener not started!");
|
||||
try
|
||||
{
|
||||
// Build Message
|
||||
@ -86,7 +90,7 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
};
|
||||
// Subscribe to ScanResultSubject
|
||||
var devicesTask = _stateResultSubject
|
||||
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(200)))
|
||||
.TakeUntil(Observable.Timer(timeout ?? TimeSpan.FromMilliseconds(250)))
|
||||
.ToTask();
|
||||
|
||||
// Send Message
|
||||
@ -228,6 +232,8 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
public void StopUdpListener()
|
||||
{
|
||||
_udpListenerActive = false;
|
||||
_udpClient.DropMulticastGroup(IPAddress.Parse(GoveeMulticastAddress));
|
||||
_udpClient.Close();
|
||||
}
|
||||
|
||||
private static void SendUdpMessage(string message, string receiverAddress, int receiverPort)
|
||||
@ -249,12 +255,13 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupUdpClientListener()
|
||||
private async void SetupUdpClientListener()
|
||||
{
|
||||
_udpClient.ExclusiveAddressUse = false;
|
||||
var localEndPoint = new IPEndPoint(IPAddress.Any, GoveeMulticastPortListen);
|
||||
_udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||
_udpClient.Client.Bind(localEndPoint);
|
||||
await StartListener();
|
||||
}
|
||||
|
||||
private async Task StartListener()
|
||||
@ -277,10 +284,9 @@ public class GoveeUdpService : IGoveeUdpService
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
catch(Exception ex)
|
||||
{
|
||||
_udpClient.DropMulticastGroup(IPAddress.Parse(GoveeMulticastAddress));
|
||||
_udpClient.Close();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ public class Program
|
||||
return GetUdpDeviceSelection();
|
||||
}
|
||||
|
||||
return _udpDevices[result];
|
||||
return _udpDevices[result-1];
|
||||
}
|
||||
|
||||
private static void HandleApiInput()
|
||||
|
@ -1,7 +1,8 @@
|
||||
# GoveeCSharpConnector
|
||||
|
||||

|
||||
[](https://www.nuget.org/packages/GoveeCSharpConnector/)
|
||||
[](https://www.nuget.org/packages/GoveeCSharpConnector/)
|
||||
|
||||
# About
|
||||
|
||||
Simple .net Library to interface with Govee Smart Lights via their Web Api or Lan Udp connection.
|
||||
|
Reference in New Issue
Block a user