Closed jaytonic closed 7 years ago
Yeah, that's what I do.. I ask the user to press the button, and just check every 3 seconds if the button has been pressed or not with a total limit of 30 seconds (like the official app).
It works fine, and if everything goes well the user only sees this once :)!
Hi @jgrossrieder
I'm handling it this way:
private async Task<string> GetApiKeyWithBridgeButtonClick(PhilipsHueBridge bridge)
{
var endTime = DateTime.UtcNow.AddSeconds(30);
var client = new LocalHueClient(bridge.IpAddress);
while (DateTime.UtcNow < endTime)
{
try
{
var machineName = Environment.MachineName.Replace(' ', '_');
if (machineName.Length > 19)
{
machineName = machineName.Substring(0, 19);
}
var appKey = await client.RegisterAsync("Xpressive.Home", machineName);
return appKey;
}
catch { }
await Task.Delay(TimeSpan.FromSeconds(1));
}
return null;
}
As you can see, I ask the user for pressing the button and then I'm polling the RegisterAsync
method every second for 30 seconds.
@niels9001 @mschuler Thank you for the answer. Thank you, I was just thinking this was not very efficient, is this a limitation from the Q42 API or from the hue API?
BTW, why do you(@mschuler) change the machine name? Is there some limitation on the API?
Yes, this is a limitation, see Point 7.1.2:
https://developers.meethue.com/documentation/configuration-api#71_create_user
Thank you
Hi,
I'm doing pretty much what the sample shows:
The issue I've is that I don't see when I should ask the user to press the link button? how the other applications does? They asks for the user to press and then try in a loop to do the RegisterAsync? Is there some kind of event that I could register to know the button has been pressed?
Thank you for the support