michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

BridgeLocator: add event that is called when a bridge is found #241

Closed pcf0 closed 3 years ago

pcf0 commented 3 years ago

This adds an event that is called when a bridge is found.

My use case is the following: I want to use the SsdpBridgeLocator. I only have one bridge in use, so that as a result, this one is enough for me. But with the current implementation, I have to wait all the time I have specified in the timeout, even though the bridge may already have been found.

With the event I can implement the following to speed things up:

var locator = new SsdpBridgeLocator();
var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
locator.BridgeFound += (s, b) =>
{
    cancelSource.Cancel();
};
var bridges = (await locator.LocateBridgesAsync(cancelSource.Token));
michielpost commented 3 years ago

Thanks for your contribution, looks good! I'll merge it and make a new release for NuGet,